Record Class BrowserState

java.lang.Object
java.lang.Record
com.codeborne.selenide.BrowserState

public record BrowserState(String origin, List<org.openqa.selenium.Cookie> cookies, Map<String,String> localStorage, Map<String,String> sessionStorage) extends Record
State of a browser for one origin: cookies, localStorage and sessionStorage.

 BrowserState state = webdriver().getBrowserState();
 String json = state.toJson();
 ...
 webdriver().restoreBrowserState(BrowserState.fromJson(json));
 
Since:
7.19.0
See Also:
  • Constructor Details

    • BrowserState

      public BrowserState(String origin, List<org.openqa.selenium.Cookie> cookies, Map<String,String> localStorage, Map<String,String> sessionStorage)
      Creates an instance of a BrowserState record class.
      Parameters:
      origin - the value for the origin record component
      cookies - the value for the cookies record component
      localStorage - the value for the localStorage record component
      sessionStorage - the value for the sessionStorage record component
  • Method Details

    • fromFile

      public static BrowserState fromFile(String file)
      Read browser state from a file (in JSON format), e.g. previously saved by BrowserSession.saveBrowserState(Path)
    • fromFile

      public static BrowserState fromFile(Path file)
      Read browser state from a file (in JSON format), e.g. previously saved by BrowserSession.saveBrowserState(Path)
    • fromJson

      public static BrowserState fromJson(String jsonText)
      Browser state as JSON string (e.g. previously generated by toJson())
    • toJson

      public String toJson()
    • toString

      public String toString()
      Cookie and storage values are not included: they are credentials.
      Specified by:
      toString in class Record
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • origin

      public String origin()
      Returns the value of the origin record component.
      Returns:
      the value of the origin record component
    • cookies

      public List<org.openqa.selenium.Cookie> cookies()
      Returns the value of the cookies record component.
      Returns:
      the value of the cookies record component
    • localStorage

      public Map<String,String> localStorage()
      Returns the value of the localStorage record component.
      Returns:
      the value of the localStorage record component
    • sessionStorage

      public Map<String,String> sessionStorage()
      Returns the value of the sessionStorage record component.
      Returns:
      the value of the sessionStorage record component