Say I am using baseurl of http://www.newtours.demoaut.com/ to login. So after login test (successful login) the base url is changed to http://newtours.demoaut.com/mercuryreservation.php?osCsid=929093474fd911e10f3a61562f069efd with a token. So this page test will be a different test but it should come from previous login. Creating two different test cases and running them as a suite is failing as the token is different each time. How to handle this??
SwitchTo().window()
in tabs index starts with 0
Related
I would like to automate the following use-case using selenium grid (nightwatch) / browserstack,
Login using 1st user
Login with 2nd user in incognito window or different browser
2nd user is a manager to 1st and interacts with user 1
Automate flows to test if 1st & 2nd user interactions works as expected
Is it possible to automate this flow? Parallel testing cannot be possible as the above use-case happens synchronously
I would like to let you know that your use case would be possible if the same is possible by you locally at your end on a local Selenium grid at your end.
Note:- You cannot open 2nd browser in the same session however you can open another tab window and also can open a session in incognito. Should you be able to open a normal browser and an incognito window in the same session locally, then you would be able to test your use case on Browserstack as well.
I am using TestCafe for my E2E testing.
Scenario: I am running a test use test runs. For example, first test run executes tests in firefox browser, and next run in chrome (this is just example, I have cases where I need to run e2e tests in different stages as well). I have used a role. When one test run completes, and it is running another test run, still the role cookie persists, and it acts as the user is logged in.
Expected behavior: Roles should be re-initialized for each run.
Is there some way I can clean the cookie, or un-initialize the roles?
The Role functionality was created to save time by saving the state of cookies and (local|session)Storage and applying them on the second and subsequent role calls. If you want to perform login actions on each test, just transfer the actions from your role to a separate function and call this function instead of the role. If your goal is different, please add the example that illustrates the current behavior and describe what task you would like to accomplish.
User Roles documentation.
I've been evaluating TestCafe for an app that requires user authentication. The documentation isn't very clear and I've had trouble getting a straight answer on how we should be using useRole.
Our application requires user authentication, right now we only test a single user so we have no need to switch user sessions.
I've defined a Role and it authenticates correctly. But I've noticed the following:
I need to call useRole first in every test in order to use the authenticated session
Every time useRole is called (first in every test) TestCafe navigates the browser back to the original login URL (or whatever preserveUrl saves post-login)
Are either of these statements wrong? I can't imagine how this works in a real environment, that's an insane amount of redirects.
Item 2 seems correct, a devexpress github contributor replied "Currently, TestCafe can't use a Role without reloading or triggering page navigation" so if I have to call useRole in every test that's literally doubling the HTTP navigation load.
The purpose of useRole is to authenticate to the app only once (per user): this means you will see the login page in the first test, and all other tests will start directly on the App page with the user being already authenticated.
The problem is that every test runs in a sandbox. The sandbox is per test and not per fixture. This means that when a test starts to execute, it starts in a brand new sandbox with no cookies and no local storage.
The only way to re-apply cookies and local storage is to call useRole. This is why useRole must be called at the beginning of each test.
useRole is a huge time saver. When I started to work with TestCafe (more than one year ago) useRole did not exist and each test would start by feeding the login page.
useRole is even more useful when you need to switch, inside a test, between different users.
And then to finish, yes, useRole reloads the App page because each test starts in a sandbox with no page history.
What you are looking for is a feature that does not exist: do not reload page between test. If you do not want to reload the page each time, do all you tests in a single test method.
I am testing a platform using testcafe for end to end tests. I have a case for testing login but I have other cases that require login.
I am not sure what is the best option I should run login on every test case setup or should run first a script login and then run all tests? I have tried both and they seem good options.
Having to log in for each and every test is time-consuming and inefficient. I would recommend having a single login for the tests if;
There is no dependency between the logged in user and the test that is running.
The actual result you are looking for can be achieved by just a single login
Furthermore, I would use 2-3 users for tests just to be cover multiple users login into the system.
TestCafe has powerful mechanism of Roles for testing login/logout functionality.
You can create Role for each user account which you would like to test and switch between them in tests. To switch to an unregistered user, you can use Role.anonymous().
The main profit of using Roles is that logging steps are executed only one time during first using of Role and next time TestCafe just reloads the page and restores required credentials.
It depends what you are testing:
If you are testing the authentication then they should login each time.
If you are testing something else then I would place this in the Arrange part of the code following the Arrange Act Assert pattern as it's not relevant to the other tests and as part of the test setup (Arrange) it should navigate back to the home page.
Ideally you isolate the authentication from other tests for performance, however if your session has some state that it has carried over from the last test you should clean this up so other tests are not effected by it.
A comment in the Git issue suggests that you can use preserveUrl to keep your session.
I want to do load test using jmeter the Login form and the page that is accessible by user after logged in. I am not getting what are the settings need to do on jmeter to test the page that looks after logged in, please explain how much you can.
The page is like homepage/mymatches.php?page=4.
you will have do the following to test the pages
Correlations refer: http://jmeter.apache.org/usermanual/regular_expressions.html
add a cookie manager to your test script.
by doing correlations using "regular expression extractor" you will be able to get/extract value of parameters from a response body/data of homepage after login and pass the same to subsequent pages where it is required.
http://apache-jmeter.blogspot.com/2011/12/correlation-regular-expression.html
hope this will help