Overview
This page explains the procedure for performing a login operation in the first scenario of a test plan and carrying over the authentication information (cookie or token) to subsequent scenarios. By configuring this, you can execute tests while maintaining the login state across multiple scenarios.
Prerequisites
To perform this procedure, confirm the cookie name and attribute information (Domain, Path, Secure, etc.) required to maintain the login state with your developer.
Steps
1. Create Workspace Variables
Refer to Creating Workspace Variables and create a variable to save the authentication information. (e.g., AUTH_TOKEN)
2. Create a Login Scenario (Get Authentication Information)
Create a scenario to be executed at the beginning of the test plan, obtain the authentication information, and save it to the workspace variable created in step 1.
Create a New scenario and record the login operation.
In the scenario editor, click Insert step and select Playwright code step.
Enter code that obtains the authentication information and returns the value, referring to the code below.
const cookies = await page.context().cookies(); // Check with the developer for the specific Cookie name const sessionCookie = cookies.find(c => c.name === 'COOKIE_NAME'); // Return the value to use in subsequent steps return sessionCookie ? sessionCookie.value : '';Below the added step, click Insert step again and select Override variable step.
For Variable to override, select the workspace variable you created in step 1.
Select Other step's output as the input method for Value.
Select the previous "Playwright code step" as the reference.
Click Save.
3. Create Subsequent Scenarios (Use Authentication Information)
Create subsequent scenarios that use the authentication information.
Create a new scenario.
Click Insert step as the first step of the scenario and add a Playwright code step.
Enter code that sets the cookie and accesses the page, referring to the code below. Note: Replace
{{AUTH_TOKEN}}with the variable name created in Step 1.
await context.addCookies([
{
name: 'COOKIE_NAME', // Actual Cookie name
value: '{{AUTH_TOKEN}}', // Specify workspace variable name
domain: 'example.com', // Target domain
path: '/',
httpOnly: true, // Set according to actual attributes
secure: true, // true for https
sameSite: 'Lax' // Set according to actual attributes
}
]);
// Specify the URL to access while logged in
await page.goto('https://example.com/dashboard/target_page');
4. Configure the Test Plan
Add the scenarios to a test plan and enable variable carry-over.
Open the Test Plans page and create a new test plan (or edit an existing one).
Add the "Login Scenario" created in Step 2 first.
Add the "Subsequent Scenarios" created in Step 3 in order.
In the test plan settings, check Carry over overridden variable values to subsequent scenarios.
Click Save.
Notes
Dependency on the application: This procedure depends on the authentication specifications of the application. If IP restrictions, token expiration, or Two-Factor Authentication (2FA) are configured, this method may not work.
Constraints on execution order: To ensure the variables are carried over, do not use parallel execution settings and fix the execution order of the scenarios.