Selenide: Restore browser state when re-creating it

Created on 23 Dec 2014  Â·  10Comments  Â·  Source: selenide/selenide

Sometimes (will try to make an isolated testcase, but not liketly to be soon), the browser crashes.

Selenide checks that in WebDriverThreadLocalContainer#getAndCheckWebDriver and reopens the browser.

It is a good idea to also restore the state (e.g. the cookies and possibly the current url)

low priority

All 10 comments

I guess we can close it. It was just an idea, it seems that nobody really needs it.

How can I re-open a webdriver or browser during the same test case run? @asolntsev

@espaciomore Can you describe your case? In which case do you need to reopen a webdriver? Why is it closed?

And what should Selenide do after re-opening the webdriver? What if browser crashed in the middle of test?

I have to run the same test multiple times, at some iteration the browser fails and the test cannot recover.

All I try to do is:

```java
public void someTestRun(){
getWebDriver();
//…
closeWebDriver();
}

@espaciomore actually you don't need to do anything. Selenide already had mechanism for tracking browser health. If browser has quited meanwhile, Selenide will open a new browser on next getWebDriver() call.

Can I understand how does Selenide do that please? I can't seem to recover and I guess it has something to do with the static condition.

Can I get the process ID for the driver that was initiated through getWebDriver()?

@espaciomore Selenide checks if browser is still open in method com.codeborne.selenide.impl.WebDriverThreadLocalContainer#isBrowserStillOpen:

  protected boolean isBrowserStillOpen(WebDriver webDriver) {
    try {
      webDriver.getTitle();
      return true;
    } catch (UnreachableBrowserException e) {
      log.log(FINE, "Browser is unreachable", e);
      return false;
    } catch (NoSuchWindowException e) {
      log.log(FINE, "Browser window is not found", e);
      return false;
    } catch (NoSuchSessionException e) {
      log.log(FINE, "Browser session is not found", e);
      return false;
    }
  }

Though, it does it only in method Selenide.open.

@espaciomore

Can I get the process ID for the driver that was initiated through getWebDriver()?

I don't know if it's possible to get the process ID. I guess it's not.

Ok, I found this method from Selenide docs getAndCheckWebDriver it new instance of WebDriver if the previous one has been closed meanwhile.

Was this page helpful?
0 / 5 - 0 ratings