Class BrowserSession

java.lang.Object
com.codeborne.selenide.BrowserSession
All Implemented Interfaces:
Conditional<org.openqa.selenium.WebDriver>

public final class BrowserSession extends Object implements Conditional<org.openqa.selenium.WebDriver>
Current browser session.

Allows checking conditions on webdriver (e.g. webdriver().shouldHave(url(...))) and saving/restoring the browser state.

  • Method Details

    • driver

      public Driver driver()
      Specified by:
      driver in interface Conditional<org.openqa.selenium.WebDriver>
      Returns:
      current Driver (used to take screenshots etc. in case of test failure)
    • object

      public org.openqa.selenium.WebDriver object()
      Specified by:
      object in interface Conditional<org.openqa.selenium.WebDriver>
      Returns:
      object under test
    • getBrowserState

      public BrowserState getBrowserState()
      Read the state of the current page: its origin, cookies, localStorage and sessionStorage.

      NB! Only cookies visible to the current page are included (as returned by WebDriver.Options.getCookies()).

      Since:
      7.19.0
    • saveBrowserState

      public void saveBrowserState(Path file)
      Save the state of the current page (its origin, cookies, localStorage and sessionStorage) to the given file. Later it can be restored with SelenideDriver.open(String, OpenOptions) or restoreBrowserState(BrowserState).
      Since:
      7.19.0
      See Also:
    • restoreBrowserState

      public void restoreBrowserState(BrowserState state)
      Add cookies, localStorage and sessionStorage items from the given state to the current page.

      Does not navigate anywhere: the current page must belong to the same origin as the state. Existing cookies and storage items are kept (unless overwritten by the state).

      Usually you don't need this method, but SelenideDriver.open(String, OpenOptions).

      Since:
      7.19.0