Skip to navigation

loadCookie

The loadCookie action loads a cookie from a file or environment variable into the browser. This action is useful for restoring authentication sessions, user preferences, or other stateful information that was previously saved using the saveCookie action.

For comprehensive options, see the loadCookie reference.

Use cases

  • Session restoration: Load previously saved authentication cookies to skip login steps
  • Test setup optimization: Reduce test execution time by reusing authentication state
  • Cross-test data sharing: Share cookies between different test specifications
  • CI/CD integration: Load authentication state from environment variables in automated pipelines
  • Test isolation: Ensure consistent starting state by loading known cookie values
  • Multi-user testing: Load different user sessions for testing various user roles

Formats

The loadCookie action supports multiple formats:

String format

Load a cookie by name from default location or by file path:

Load from environment variable
{
"loadCookie": "session_token"
}
Load from file
{
"loadCookie": "session_token.txt"
}

Object format

Load a cookie with detailed configuration:

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

Configuration options

FieldTypeDescriptionDefault
namestringRequired. Name of the specific cookie to load.
variablestringEnvironment variable name containing the cookie as JSON string. Can’t be used with path.
pathstringFile path to cookie file, relative to directory. Supports Netscape cookie format. Can’t be used with variable.
directorystringDirectory containing the cookie file.
domainstringSpecific domain to filter the cookie by when loading from multi-cookie file (optional).

Examples

Load from default location

{
"steps": [
{
"description": "Load saved session cookie",
"loadCookie": "session_token"
},
{
"description": "Navigate to protected page",
"goTo": "https://example.com/dashboard"
}
]
}

Load from specific file

{
"steps": [
{
"description": "Load authentication cookie from file",
"loadCookie": {
"name": "auth_cookie",
"path": "auth-session.txt",
"directory": "./test-data"
}
}
]
}

Load from environment variable

{
"steps": [
{
"description": "Load session cookie from environment variable",
"loadCookie": {
"name": "session_token",
"variable": "SESSION_TOKEN"
}
}
]
}

Load with domain filtering

{
"steps": [
{
"description": "Load cookie for specific domain from multi-cookie file",
"loadCookie": {
"name": "user_session",
"path": "saved-cookies.txt",
"domain": "app.example.com"
}
}
]
}

Complete workflow example

{
"tests": [
{
"description": "Setup test - authenticate and save session",
"steps": [
{
"description": "Navigate to login page",
"goTo": "https://example.com/login"
},
{
"description": "Enter credentials and login",
"find": {
"elementText": "Username",
"type": "testuser"
}
},
{
"description": "Save authentication cookie",
"saveCookie": {
"name": "session_token",
"path": "session.txt"
}
}
]
},
{
"description": "Main test - use saved session",
"steps": [
{
"description": "Load saved authentication cookie",
"loadCookie": {
"name": "session_token",
"path": "session.txt"
}
},
{
"description": "Navigate directly to protected page",
"goTo": "https://example.com/dashboard"
},
{
"description": "Verify authenticated access",
"find": {
"elementText": "Welcome back"
}
}
]
}
]
}
  • saveCookie: Save a browser cookie to a file or environment variable
  • loadVariables: Load environment variables from .env files