Skip to navigation

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.

For comprehensive options, see the saveCookie reference.

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

Save a cookie by name to a default location:

Save to environment variable
{
"saveCookie": "session_token"
}
Save to file
{
"saveCookie": "session_token.txt"
}

Object format

Save a cookie with detailed configuration:

{
"saveCookie": {
"name": "auth_cookie",
"path": "auth-session.txt",
"directory": "./test-data",
"overwrite": "true"
}
}

Configuration options

FieldTypeDescriptionDefault
namestringRequired. Name of the specific cookie to save.
variablestringEnvironment variable name to store the cookie as JSON string. Can’t be used with path.
pathstringFile path to save the cookie, relative to directory. Uses Netscape cookie format. Can’t be used with variable.
directorystringDirectory to save the cookie file. If not specified, uses output directory.
overwritestringWhether to overwrite existing cookie file. Options: "true", "false"."false"
domainstringSpecific domain to filter the cookie by (optional).

Examples

Save to default location

{
"steps": [
{
"description": "Navigate to login page and authenticate",
"goTo": "https://example.com/login"
},
{
"description": "Fill in login credentials",
"find": {
"elementText": "Username",
"type": "testuser"
}
},
{
"description": "Save the session cookie after login",
"saveCookie": "session_token"
}
]
}

Save to specific file

{
"steps": [
{
"description": "Save authentication cookie to specific file",
"saveCookie": {
"name": "auth_cookie",
"path": "auth-session.txt",
"directory": "./test-data",
"overwrite": "true"
}
}
]
}

Save to environment variable

{
"steps": [
{
"description": "Save session cookie to environment variable",
"saveCookie": {
"name": "session_token",
"variable": "SESSION_TOKEN"
}
}
]
}

Save with domain filtering

{
"steps": [
{
"description": "Save cookie for specific domain",
"saveCookie": {
"name": "login_token",
"path": "login-token.txt",
"domain": "app.example.com"
}
}
]
}