PlaywrightHelperfunctions
Install
Import
First time setup of Playwright
After installing omniweb and have that build running you can start with playwright.
First, add playwright in your package.json, like this:
Then you need to install the browsers:
Environment Variables
Playwright uses several environment variables that can be configured in a playwright.env file or set directly in your environment:
Legacy/Cypress Compatibility
The following Cypress environment variables are also supported for compatibility:
PLAYWRIGHT_BASE_URL- Falls back toCYPRESS_baseUrlif not setPLAYWRIGHT_API_URL- Falls back toCYPRESS_apiUrlif not set
Required Environment Variables
-
PLAYWRIGHT_BASE_URL- The base URL for the application under test- Default:
http://localhost:3000 - Example:
PLAYWRIGHT_BASE_URL="http://localhost:3000"
- Default:
-
PLAYWRIGHT_API_URL- The API URL for backend services- Default:
https://api.qa01.norsk-tipping.no(based on NT_ENVDOMAIN) - Example:
PLAYWRIGHT_API_URL="https://api.qa01.norsk-tipping.no"
- Default:
Optional Environment Variables
-
NT_ENVDOMAIN- The environment domain for Norsk Tipping services- Default:
qa01 - Supported values:
qa01,int,stage,dev - Used to construct API URLs, authentication endpoints, and the test user pool endpoint
- Example:
NT_ENVDOMAIN="stage"
- Default:
-
PLAYWRIGHT_USER_BUYPASS_ID- Specific user ID for testing- Default: Empty (will fetch from user pool)
- If not set, tests will fetch a user from the test user pool for the configured
NT_ENVDOMAIN - Example:
PLAYWRIGHT_USER_BUYPASS_ID="123456789"
Usage
The test fixture automatically:
- Acquires a test user account for authenticated tests
- Handles authentication
- Resets the authenticated user state before tests run
- Sets up storage state with
localStorageDefaultsandntToken - Configures modal interception
Authenticated and guest tests
For authenticated tests, use SomeTestName.spec.ts.
For tests without authentication, use SomeTestName.guest.spec.ts,
and import defaultStorageState:
Playwright automatically handles authentication for tests by:
- Fetching a test user from the environment-specific user pool (unless
PLAYWRIGHT_USER_BUYPASS_IDis specified) - Obtaining authentication tokens from the environment-specific test authentication service
- Setting up storage state with the required tokens and localStorage defaults
Desktop tests (baseConfig)
If you use baseConfig you can run tests only on desktop project by naming the tests SomeTestName.desktop.spec.ts
or SomeTestName.guest.desktop.spec.ts for non-authenticated tests (if you also import defaultStorageState).
Change test path
If you use the baseConfig as your standard playwright configuration and want to override the test path, you can do:
(supports --ui and filters like the one described under "Pipeline tets")