saveCookie
The saveCookie action saves a browser cookie to a file or environment variable for later reuse. This action is useful for preserving authentication sessions, user preferences, or other stateful information between test runs or across different tests.
Reload saved cookies with the loadCookie action.
Secrets in output: A cookie file holds the real cookie value, because loadCookie reads it back. Unlike the output files that actions such as runShell, runCode, httpRequest, and runBrowserScript save with path, it isn’t masked. An authentication cookie works like a password. Add the cookie file’s folder (directory, or outputDir by default) to .gitignore, and leave it out of uploaded CI artifacts.
A cookie saved with variable holds the real value too. Saving it doesn’t register it for masking, even when the variable’s name looks secret. Logs and reports mask it only after a later step substitutes it as $NAME in a step field. That field can be a URL, a selector, or a header value. Loading the cookie with loadCookie doesn’t register it for masking.
A runShell or runCode command that reads the cookie variable from its environment prints the real cookie. Don’t print the variable or list the environment in those commands. See Keep secrets out of logs, reports, and captures.
For comprehensive options, see the
saveCookiereference.
Use cases
- Session persistence: Save authentication cookies to maintain login state across test runs
- Multi-step workflows: Preserve cookies between different test specifications
- Cross-browser testing: Transfer cookies between different browser contexts
- CI/CD integration: Store authentication state as environment variables for automated testing
- Test data management: Save cookies to files for debugging and test data inspection
Formats
The saveCookie action supports multiple formats:
String format
A cookie name saves that cookie to the environment variable of the same name. A path ending in .txt saves the cookie named for the file, session_token here, to that path in outputDir:
Object format
Save a cookie with detailed configuration:
Configuration options
The object form requires name plus exactly one of path or variable. Set path to write a cookie file, or variable to store the cookie in an environment variable, but not both. Omitting both fails validation.
overwrite here is a plain boolean (true or false). This differs from the regression-testing actions, where overwrite is the string enum "true", "false", or "aboveVariation". Those actions are screenshot, record, httpRequest, runCode, runShell, and runBrowserScript.
Examples
The docs tests run every example below except the specific-file example.
Save to default location
Save to specific file
Save to environment variable
Save with domain filtering
Related actions
loadCookie: Load a saved cookie back into the browserloadVariables: Load environment variables from .env files