简体   繁体   中英

How to run Parallel Tests in Selenium using different user credentials?

I am trying to run the tests in Parallel for my automated test cases, but i need to execute them with different user credentials.

So i want to make it as if each of the threads executed at any point of time should not have the application open as the same user. My application is such that the view for a user will be retained and if the same user is accessing the application as different threads doing different actions it will lead to failure of test cases.

Hence i need to know if there is way out by which I can run the test cases in parallel using the testng xml, but these parallely executing test cases should be using different login credentials stored somewhere in the framework.

How can i do this ?? Please help me with the necessary approach

Create document with values like username, password and test id and assign each test with its own credentials. In tests read from the doc credentials based on test id.

Of course you can assign users before each execution.

In automated testcases you can run the tests by different user logins by reading data that is username and password from a csv file.
Or you can integrate with Cucumber where in feature file itself you can provide different credentials.

You can try this approach.

  1. Create a database table USERS_ACCOUNTS in any database server (MySQl or Oracle).
  2. Store your user-related information.
  3. Add a column IS_CURRENTLY_USED to your USERS_ACCOUNTS table which stores whether the user is currently logged in or not.
  4. Now in the login method of your test script don't get the user from csv or config.
  5. Instead, get the user from the USERS_ACCOUNTS table where IS_CURRENTLY_USED value is false.
  6. Then update the IS_CURRENTLY_USED column to true so that your other tests will not get logged in user.
  7. Make sure you do the above 2 steps as one transaction to avoid tests getting the same user.

I can share the code if you want.

When you instantiate a WebDriver , it will be binded to a unique session in Web Browser, that's why when you want to do parallel tests with the same WebDriver , first, it will connect with the first user then the session will remember your credentials and you won't be able to test with another user. I think that you have for every user instantiate a WebDriver so that you can do parallel tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM