Package com.codeborne.selenide
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 Summary
Modifier and TypeMethodDescriptiondriver()Read the state of the current page: its origin, cookies, localStorage and sessionStorage.org.openqa.selenium.WebDriverobject()voidrestoreBrowserState(BrowserState state) Add cookies, localStorage and sessionStorage items from the given state to the current page.voidsaveBrowserState(Path file) Save the state of the current page (its origin, cookies, localStorage and sessionStorage) to the given file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.codeborne.selenide.Conditional
shouldHave, shouldHave, shouldNotHave, shouldNotHave
-
Method Details
-
driver
- Specified by:
driverin interfaceConditional<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:
objectin interfaceConditional<org.openqa.selenium.WebDriver>- Returns:
- object under test
-
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
Save the state of the current page (its origin, cookies, localStorage and sessionStorage) to the given file. Later it can be restored withSelenideDriver.open(String, OpenOptions)orrestoreBrowserState(BrowserState).- Since:
- 7.19.0
- See Also:
-
restoreBrowserState
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
-