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_baseUrl
if not setPLAYWRIGHT_API_URL
- Falls back toCYPRESS_apiUrl
if 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
- Used to construct API URLs and authentication endpoints
- Example:
NT_ENVDOMAIN="qa01"
- 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
- Example:
PLAYWRIGHT_USER_BUYPASS_ID="123456789"
Usage
The test fixture automatically:
- Acquires a test user account for authenticated tests
- Handles authentication
- Sets up proper storage state with cookies accepted
- Configures modal interception
Authenticated and guest tests
For authenticated tests, use SomeTestName.spec.ts
.
For tests without authenticated, use SomeTestName.guest.spec.ts
,
and import defaultStorageState
:
Playwright automatically handles authentication for tests by:
- Fetching a test user from the user pool (unless
PLAYWRIGHT_USER_BUYPASS_ID
is specified) - Obtaining authentication tokens from the 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")