java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.RestoreSessionState
All Implemented Interfaces:
net.serenitybdd.core.SkipNested, net.serenitybdd.screenplay.Performable

public class RestoreSessionState extends Object implements net.serenitybdd.screenplay.Performable
Restore browser session state (cookies, localStorage, sessionStorage) from a previously saved file. This allows skipping login flows by reusing authentication state across tests.

The restored state includes:

  • All cookies from the saved context
  • localStorage data for all origins
  • sessionStorage data for all origins

Sample usage:

     // In a setup class or @BeforeAll, save auth state once:
     actor.attemptsTo(
         Navigate.to(loginPage),
         Enter.theValue("user@example.com").into("#email"),
         Enter.theValue("password").into("#password"),
         Click.on("#login-btn"),
         SaveSessionState.toFile("auth-state")
     );

     // In subsequent tests, restore the state to skip login:
     actor.attemptsTo(RestoreSessionState.fromFile("auth-state"));

     // Actor is now authenticated - navigate directly to protected pages
     actor.attemptsTo(Navigate.to(dashboardPage));
 

Important: This interaction creates a new browser context with the saved state. Any existing pages will be closed. Call this early in your test setup.

See Also:
  • Method Details

    • fromFile

      public static RestoreSessionState fromFile(String name)
      Restore session state from a file with the given name in the default directory. The file should exist at: target/playwright/session-state/{name}.json
      Parameters:
      name - The name of the state file (without extension)
    • fromPath

      public static RestoreSessionState fromPath(Path path)
      Restore session state from the specified path.
      Parameters:
      path - The full path to the state file
    • fromPath

      public static RestoreSessionState fromPath(String path)
      Restore session state from the specified path.
      Parameters:
      path - The full path to the state file
    • performAs

      public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor)
      Specified by:
      performAs in interface net.serenitybdd.screenplay.Performable
    • getInputPath

      public Path getInputPath()
      Get the path from which the session state will be restored.