Jeyabal
Jeyabal

Reputation: 71

Selenium; How to run multiple instances and maintain different session

I know we can run tests in multiple browsers using testng and selenium grid. But, the problem am facing is, Second browser is taking the logged in session of first browser.

I mean, I need to sign in to an web-application and do some functional flow automation. Code is ready and running fine stand alone. Facing issue when executing in two instances of firefox, or chrome. Firefox1 logged in first and Firefox2 also takes the session before login step. If Firefox2 logout, Firefox1 also logged out before reaching logout step.

Upvotes: 3

Views: 5069

Answers (2)

Niels van Reijmersdal
Niels van Reijmersdal

Reputation: 2045

Out of the box a new Selenium WebDriver instance uses an empty profile, unless you specify otherwise.

Sounds like you are using the same user for both test runs. When the users log-out or in it gets the same session state as in all other locations. Thus it is again on the same page or logged-out. I would ask the developers to explain how the session management works for your application.

Test insolation:

You will need to isolate the test-data and or test-environment for each parallel run. You could start with creating a new user for your test before you start the test.

See this answer for more idea's how to isolate tests from each other: https://sqa.stackexchange.com/a/25623/3201

Other reads:

Upvotes: 2

Anton Angelov
Anton Angelov

Reputation: 1713

Most probably when you logged in your web application is storing the session in a permanent cookie. You can try to delete these cookies after loading the site's URL.

webDriver.Manage().Cookies.DeleteAllCookies();

Upvotes: 1

Related Questions