Class OpenOptions

java.lang.Object
com.codeborne.selenide.OpenOptions

public final class OpenOptions extends Object
Options for opening a page: SelenideDriver.open(String, OpenOptions).

Allows skipping the login in tests: log in once, save the browser state to a file, and restore it in other tests.


 open("/dashboard", withBrowserState("build/auth.json")
   .loggedInIf(() -> $("#logout").is(visible, Duration.ofSeconds(2)))
   .orLogin(() -> login("bob", "secret")));
 
Since:
7.19.0
See Also:
  • Method Details

    • withBrowserState

      public static OpenOptions withBrowserState(String file)
      Restore browser state from the given file (in JSON format) before opening the page. The file is not read immediately, but only when the page is being opened.
      See Also:
    • withBrowserState

      public static OpenOptions withBrowserState(Path file)
      Restore browser state from the given file (in JSON format) before opening the page. The file is not read immediately, but only when the page is being opened.
      See Also:
    • withBrowserState

      public static OpenOptions withBrowserState(BrowserState browserState)
      Restore the given browser state before opening the page.
    • loggedInIf

      public OpenOptions loggedInIf(BooleanSupplier loggedInCheck)
      Check if user is logged in. Used together with orLogin(Runnable).
      Parameters:
      loggedInCheck - returns true if user is logged in (after restoring the state and opening the page)
    • orLogin

      public OpenOptions orLogin(Runnable login)
      Log in if the file doesn't exist yet, or if the saved state is not valid anymore (as reported by loggedInIf(BooleanSupplier)). After logging in, the browser state is saved to the file.
      Parameters:
      login - code that logs user in (opens login page, enters credentials etc.)
    • toString

      public String toString()
      Overrides:
      toString in class Object