Logging in with different Users.

26 views
Skip to first unread message

Santosh Pillai

unread,
Apr 24, 2017, 6:26:16 AM4/24/17
to webdriver

​I've a simple use case for my application.


1. login with 'user1' and verify something.

2. Logout.

3. Clear browser cookies.

4. Login with 'user2' and verify something else.


Actual behavior: At step 4, I'm getting logged in with 'user1' again.

Browsers covered: Firefox and Chrome.


What I've tried so far?

- driver.manage().deleteAllCookies();​ between step 3 and 4. But its not working. Still getting logged in the previous user.

- driver.navigate().refresh();​ between step 3 and 4. But its not working. Still getting logged in the previous user.​

Also, if I check the cookies after logging in to the application, its 0.

Set<Cookie> allCookies = driver.manage().getCookies();
 System.out.println("Total Cookies " + allCookies.size());


Can anyone please help me with a workaround?


Thanks,

Santosh


darrell grainger

unread,
Apr 24, 2017, 8:59:45 AM4/24/17
to webdriver
First I'm curious if this works manually. Can you do the steps manually? If you can open Chrome, log in as user1, logout, clear cookies, log in as user2 then maybe the clear cookies feature of Selenium isn't working.

However, if you find you are doing something slightly different manually then that might have clues to what you need to do with Selenium. For example, if the exact steps, manually, are:
  1. Go to login page
  2. Login as user1
  3. Verify something
  4. Logout
  5. Clear browser cookies
  6. Refresh browser page
  7. Login as user2
That extra step of refreshing the browser page might be what is necessary. Or maybe you are closing the original tab and opening a new tab then logging in as user2. To simulate that in Selenium it would be:
  1. Go to login page
  2. Login as user1
  3. Verify something
  4. Logout
  5. Clear browser cookies
  6. driver.close() to close the original tab
  7. driver = new ChromeDriver() to open a new tab
  8. Login in as user2
Bottom line, make sure the scenario works manually then figure out the extra same steps in Selenium. If you have ALL the steps for it to work manually you could post them and we can tell you how to do the exact same thing in Selenium.

Darrell
Reply all
Reply to author
Forward
0 new messages