Google Optimization for e2e test with protractor - javascript

Login optimization should be implemented in order to speed up the execution time of all e2e tests. Currently, after each test we have, the Chrome browser closes, and the next session login should be done again in order to proceed with another test. How and what should be changed regarding this matter. Any advice?

Unfortunately without details of how your application works, i can suggest only some generic things:
Usually applications store something like session token in cookies, you can try to grab it, and set again after browser reloaded. Make sure you are trying to set cookie after page is opened. Docs to read:
browser.manage().addCookie(...)
https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html#addCookie
You can try to make HTTP request from the page with needed credentials, so cookies that you will got in response will be set to page. To do this you can use browser.executeScript(...) with fetch/XMLhttprequest inside

You might think about running a selenium grid with different selenium nodes. Your browser instances can be configured to run in the selenium grid endlessly if you do not run browser.quit or browser.close at the end of each test. That way using the method Xotabu4 mentioned above, you can set the browser cookie using browser.manage().addCookie(...). You can also clean the browser cookies if required.
Now your running browser instance will have the auth cookie for the tests you are running and you will no longer have to worry about login. These tests are better if you run it in a selenium grid using docker containers because you can monitor different chrome/firefox nodes and if any of them die or restart. You will have to configure the chrome node containers in such a way that everytime a node is restarted, you add auth cookies to your browser.
Another suggestion I have for you is to disable authentication check in your automated test environment and test authentication in a different environment. I know the quality of this advice would vary depending on your application.
Every test scenario requiring login runs the login function before running any other tests everytime. One thing common in this is the login functionality. If you abstract that functionality out and ensure that functionality is working well and then disable that functionality and test everything else. You will save a lot of time. Only thing you need to be sure about here is that the login functionality integrates with the rest of the moving parts of your application in exactly the same way.

Related

How to manually view the webpage before the tests run in cypress?

I have a webpage in which i want to test all the data and the top results, but before i am able to do that i am required to authenticate via a phone. The main problem is that I have to prove that i am not a robot via a captcha and also authenticate the phone with a phone call. All of this, as i believe, is done manually (we can't remove the captcha or the phone verification from the test process). How do I first without the help of cypress login, and then set up all the tests?
I had tried to login in between the tests, yet they couldn't continue after my interaction.
All such login procedures should be disabled on test environments. Simply because you have no control over them. The only result of trying to work around such GUI authentication schemes is you will make your tests flaky. Not even mentioning problems with different domains in Cypress.
If there is such an authentication, it's much better to use an API, e.g. like described here for Auth0. But that requires some setup in Auth0, and then some Cypress code.

How do I detect when a user closes their browser?

I am trying to set something up in my application so that I can detect if two users are editing the same document at the same time. The best way I could think to do this was by sending information to the backend when a user logs in and logs out, and checking that when I want to see if two users are active at the same time. Starting the application is easy to detect with useEffect, but I'm having trouble finding a way to do so cleanly.
I looked at the onunload and onbeforeunload, but those don't seem to have universal browser support, and I'd prefer to not disrupt the user experience with a popup. I was thinking about checking for idle, but if there's a cleaner method, such as something with Google Cloud Platform, that would be helpful. Thanks!
That sounds like a great use case for onDisconnect. You can read more about it here and here.
This would be a simple example:
var ref = firebase.database().ref("onlineState");
ref.onDisconnect().set(false);
What happens here is that this command is send to Firebase and lives there. When you lose connection to Firebase it will be executed. It doesn't matter if it's done by closing the browser/tab etc...
If you need a more complex code execution then attach a firebase cloud function trigger to those changes. It's importand to know that you can't execute client side code on that event.

Login to Azure-Active Directory from cypress tests

I have to write automation tests for application that requires login to Azure Active Directory.
The tests are written with cypress and TypeScript.
Im looking for an idea how to do login from my tests with user name and password.
The login process must include 2FA.
I tried to do it in interactive mode, but I had a problem how to get the OTP, This is the reason that I want to do the login in non-interactive mode.
Any idea how to login programmatically?
When I've talked to people on the AAD product team, they've usually said it's not a good idea to try to automate the login UI.
They have checks in place to check for odd behaviour and this could trip those, breaking your tests.
I don't have a good solution to offer for this.
You could somehow inject tokens into your front-end that you acquired in a different way.
ROPC is an option but won't support MFA.
Another is to bootstrap the process manually and keep a refresh token somewhere that you can then use to get tokens.

Is it possible to test flow using Protractor without login flow?

I want to test flow using Protractor which occurs after login page, can I bypass or skip or avoid login while testing that flow?
One option would be to instead of opening a fresh browser instance each test, you open Firefox loading the Firefox profile previously saved when you was logged in. Aside from many other things, the profile contains cookies, that are usually used for login session validation:
log in to your application via Firefox
open Help->Troubleshooting Information->Profile Folder->Show in Finder (for Mac OS)
copy the path to the profile
use setFirefoxProfile HowTo to learn how to load this profile every time you run your tests
You can always mock the login, where details will depend on how the login is implemented.
If it is the session or key returned by the server, you can mock the server response by supplying that key, that will be accepted by your front end code, as if there was successful login.

Updating Web App code without reloading it

Is there any way or possibility to update an apps code and have the client adopt it without reloading the app/website? I mean updating live application code, like adding or removing functionality.
The iPad asks for user permission every 24 hours for fullscreen webapps, for native apps it does not. Once you grant permission it will not ask again but if you reload the app, which you usually have to when you push an update, it will ask again if 24h passed.
We are installing iPads into Taxis and want to track connectivity around the city with geolocation data, but we can't do it reliably since the app would ask the guest for permission. We also would like to provide some location based features but wen can't do it because if one guest says "No", it will impact all next guests since the iPad only allows aksing twice and then you have to wait some time before you can ask for using Geolocation again,
By update the code I presume you mean live code reload or changing the modules loaded on a page without changing it.
This would require you to have an infrastructure library that allows you to either reload or add modules of code to your applications. ncore allows this
Next you would need a communication channel from the server or some other remote end point to send new modules or module reload commands to the client browser.
The concept being that you have a websocket open and you send one of two commands
add module : url
reload module : name
The app in the browser would then either load and add that module from an url or reload that module.
This is basically remote control over the state of an application in a users browser.

Categories