Class RestoreSessionState
java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.RestoreSessionState
- All Implemented Interfaces:
net.serenitybdd.core.SkipNested,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 Summary
Modifier and TypeMethodDescriptionstatic RestoreSessionStateRestore session state from a file with the given name in the default directory.static RestoreSessionStateRestore session state from the specified path.static RestoreSessionStateRestore session state from the specified path.Get the path from which the session state will be restored.<T extends net.serenitybdd.screenplay.Actor>
voidperformAs(T actor) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.serenitybdd.screenplay.Performable
then
-
Method Details
-
fromFile
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
Restore session state from the specified path.- Parameters:
path- The full path to the state file
-
fromPath
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:
performAsin interfacenet.serenitybdd.screenplay.Performable
-
getInputPath
Get the path from which the session state will be restored.
-