4

Microsoft Edge driver does not ensure clean session whenever it runs selenium tests. Is there an option I can specify to desired capabilities to fix this?

EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40
Chris Hansen
  • 7,813
  • 15
  • 81
  • 165
  • what do you mean by saying 'clean session'? If you're talking about cookies stored in edge, then you're able to clean them using `driver.manage().deleteAllCookies();` – Mikhail Sep 21 '16 at 16:49
  • i want to clear cache, cookies, and history. In IE, you can just specify the property ie.ensureCleanSession = true in desiredCapabilities to get that done – Chris Hansen Sep 21 '16 at 17:01
  • 1
    Note: driver.manage().deleteAllCookies() is not working on Release 14393 MS edge Win 10 Sel 3.1.0 – Kozi Apr 04 '17 at 09:23
  • @Kozi, It works, but first you need to have a page open. See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5751773/#comment-2 – André Apr 05 '17 at 00:23
  • @André Is it work for localhost? after opening a page from localhost it doesn't delete cookies. – mihkov Dec 27 '18 at 07:50

3 Answers3

5

Just encounter that issue myself today so the only way I got it to work was pretty simple in the end. You have to check "Always clear this when I close the browser" in Edge settings (and select the things that you want to clear).

With that setting you will have clean session on each new driver initialization :) selenium edge clean session

Rain9333
  • 570
  • 4
  • 22
2

Another solution could be to open Edge in Private Mode (at least solved my problems with session and clearing cookies):

EdgeOptions options = new EdgeOptions();
options.AddAdditionalCapability("InPrivate", true);
this.edgeDriver = new EdgeDriver(options);
mihkov
  • 1,171
  • 13
  • 37
0

From my experience, the only way to achieve a clean session in Edge is to build it as you go. What I mean is, you must clear cookies and reload screens where necessary.

An example would be a login screen which navigates to a landing page having a popup arrive ~1-3 seconds after load.

  • Edge login pages typically don't logout the previous tests user so a Logout is often required at the beginning of these test steps if Browser=Edge.

  • The first time this all happens locally, the driver sees the popup, it's dismissed, and a cookie gets created which prevents the popup from triggering for the next test.

I don't know about your test framework, but I use ConfirmOnThisPage() methods anytime I move from one page to another. So, once I know the page has loaded, I can easily handle cookies about to be tested here with a call to a DeleteCookie(Cookie cookie) function which contains a page refresh from within my page confirmation method. I use the following:

public IWebDriver DeleteCookie(Cookie cookie){
    driver.Manage().Cookies.DeleteCookieNamed(cookie);
    driver.Navigate().Refresh(); 
    return driver;
}
LoflinA
  • 350
  • 4
  • 19