Login and logout with different user credentials

satmisha
satmisha used Ask the Experts™
on
Hi experts,

Using;
Selenium, Chrome Browser, C#, nUnit:

My scenario is ::
1. I need to login to my application ( chrome browser), process Test Case.
2. Logout, close browser window
3. Open new chrome window.
4. Re-launch the browser with the same URL
5. Login again with different user6. process test cases
6. Logout.

What I am doing:
When I close browser and launched new URL and tries to login with different credentials I get the below error:

Problem:
Getting this exception:
"invalid session id\n  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)"

Please help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
SteveArchitect/Designer

Commented:
check the url you're opening initially. it may contain session info if it was bookmarked/copied when logged in with the first user.

Author

Commented:
Thanks steve, I have checked that and URL appears to me normal, I have hardcoded that for the time being indeed which is same.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
As Steve suggests, session info is somehow following you.

Glancing at the docs (I only took a few minutes) I'm missing how the default cookie file is handled.

My guess is you're defaulting to use some common cookie file, rather than creating a new/random/unique cookie file for each session.

Try creating a /tmp cookie file made up of procname + pid + username + 16byte random alphanumeric string, then destroy this file when you exit.

This should at least fix any carry over session problems.

Author

Commented:
Thanks David, providing little more details:

[TestMethod]
public void ClickingAllTheEnglishPageLinks() // Starting the automation framework from the main
{
	Driver = new ChromeDriver();
	Implicitlywait();
	Driver.Navigate().GoToUrl(websiteUrl);
	Driver.Manage().Window.Maximize();

	LoginWithUserA();
	Driver.CloseBrowser();
	
	LoginWithUserB();
	 /*********getting this exception, moment click on Login Button****
	 Problem: 
	Getting this exception: 
	"invalid session id\n  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)"
	*************************************************************************************************************/
}

Open in new window


What I am doing in the above case, unable to understand?
Commented:
I was closing the web browser and opening the new browser which caused me above mentioned problem. So I signed out and re-login within the same browser to get rid of this error.

It worked for me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial