0

I am using selenium-* 4.0.0 in java to do some UI automation work, with a chrome webdriver. Essentially the flow is login -> page 1 -> logout.

It worked beautifully when driver loads the login page first time. But after I login, even after I loads logout page, which finishes successfully (I have waited long enough to make sure the final link appears), my 2nd loading of the login page fails, it directly goes to page 1, as the user session still exists. But I am trying to login 2nd time with another user.

I have tried

  1. loading logout page (logout page is loaded correctly, but user data still exists)
  2. using devtools to devTools.send(Network.clearBrowserCookies()); OR devTools.send(Network.clearBrowserCache());
  3. deleteAllCookies (Actually I don't want to delete all cookies. Just want to clear user login data)
  4. driver.quit
  5. driver.close

none works. I am doing the test through a test container, which has one webdriver. Not very willing to stop/restart the container just to get a new webdriver, before I have explored all possibilities to reuse the webdriver.

Can anyone please share some opinion on how to logout user in selenium webdriver? Many thanks

gigi2
  • 1,996
  • 1
  • 17
  • 22
  • What is the issue with `deleteAllCookies`? – undetected Selenium Dec 09 '21 at 20:20
  • You need to show your code. You may not have allowed time for logout to complete. – pcalkins Dec 09 '21 at 20:34
  • after deleteAllCookies, the rest of my flow is not working. Odd things show up with page 1, but still without relogin :( I did wait until the final link of logout to show up, as I would see in my manual test, and it did in my selenium test – gigi2 Dec 10 '21 at 17:14

1 Answers1

0
  1. deleteAllCookies sounds promising, if it does not work you can try to delete only the cookie that is connected to the logged user data. Double check it is logging out the user when you delete it manually in order to be sure that the issue is not in your automation script.

  2. You can try to use incognito mode of the browser

    chrome_options.add_argument("--incognito")

  3. There could be application cache bug and the logged version of the page can be cached by your application. I do not know if your application cache varies by query string, but you can try something like http://yourdomainname.com?test=somevalue. If there is such bug, it should be fixed with critical priority.

  4. Also there can be browser cache and Ctrl + F5 after logout may help. You can try also this code:

    devTools.send(setCacheDisabled(true)); I got if from Disable cache in Selenium Chrome Driver

  5. You can also try to delete localStorage or SessionStorage and see if it helps.

K. B.
  • 3,342
  • 3
  • 19
  • 32
  • Later I dived into the source code of webdriver, it appears there is a session started right in the constructor of webdriver. and either webdriver or session itself does NOT provide a way to renew/restart the session for the webdriver. I doubt whether re-login suits the design of webdriver instance after that. Not sure if anyone has done it – gigi2 Dec 10 '21 at 20:10
  • Thank you for all the suggestions, K.B. Appreciate it. Not working for me, unfortunately :( I did manually check logout. It works when I am doing it in browser. But not with selenium webdriver. – gigi2 Dec 10 '21 at 20:11