Class SaveSessionState
java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.SaveSessionState
- All Implemented Interfaces:
net.serenitybdd.core.SkipNested,net.serenitybdd.screenplay.Performable
Save the current browser session state (cookies, localStorage, sessionStorage) to a file.
This allows reusing authentication state across tests, significantly speeding up test suites.
The saved state includes:
- All cookies from the browser context
- localStorage data for all origins
- sessionStorage data for all origins
Sample usage:
// After logging in, save the session state
actor.attemptsTo(
Navigate.to(loginPage),
Enter.theValue("user@example.com").into("#email"),
Enter.theValue("password").into("#password"),
Click.on("#login-btn")
);
// Save the authenticated state to a file
actor.attemptsTo(SaveSessionState.toFile("auth-state.json"));
// In subsequent tests, restore the state to skip login
actor.attemptsTo(RestoreSessionState.fromFile("auth-state.json"));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGet the path where the session state will be saved.<T extends net.serenitybdd.screenplay.Actor>
voidperformAs(T actor) static SaveSessionStateSave session state to a file with the given name in the default directory.static SaveSessionStateSave session state to the specified path.static SaveSessionStateSave session state to the specified path.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
-
toFile
Save session state to a file with the given name in the default directory. The file will be saved as: target/playwright/session-state/{name}.json- Parameters:
name- The name for the state file (without extension)
-
toPath
Save session state to the specified path.- Parameters:
path- The full path for the state file
-
toPath
Save session state to the specified path.- Parameters:
path- The full path for the state file
-
performAs
public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor) - Specified by:
performAsin interfacenet.serenitybdd.screenplay.Performable
-
getOutputPath
Get the path where the session state will be saved.
-