I am using Selenium Grid with TestNG to run my tests in parallel. I have certain tests that require a user to be logged in, so I have a user account configured for testing.
I have been careful to ensure that any tests involving logging in as my test user are run on separate virtual machines so that sessions are not interrupted, however after investigating some regularly failing tests it turns out that this is not enough. I therefore either need to:
-
Set up a new user for each test (I understand this may be the ideal solution, but it’ll take some time to configure/run.
-
Have multiple test user accounts, and ensure that only one is used at a time.
If I could identify the host of the machine running the test I could set up test accounts accordingly. Is there any way to do this, or is there another solution that I haven’t thought of?
I solved my problem by setting up several unique user accounts purely for testing, all ending with a number (for example: selenium.test1). This was simple to automate as a one off task using Selenium.
I store this number in code, and every time a test needs to login the number is incremented and the username is constructed.
I did consider ‘releasing’ and subsequently reusing these accounts when the tests finish, but decided it was easier just to make sure I had plenty of test accounts for my tests.