-
Notifications
You must be signed in to change notification settings - Fork 5
/
playwright.config.ts
167 lines (157 loc) · 5.72 KB
/
playwright.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* playwright.config.ts: This module is responsible for configuring the Playwright test runner.
* It includes settings for test execution, browser configuration, and environment variables.
* See https://playwright.dev/docs/test-configuration for more details.
*/
import { ACTION_TIMEOUT, EXPECT_TIMEOUT, NAVIGATION_TIMEOUT, TEST_TIMEOUT } from 'utils/timeout-constants';
import { WaitForLoadStateOptions } from 'setup/optional-parameter-types';
import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
const BASE_URL = process.env.URL || 'https://www.saucedemo.com/';
const startLocalHost = process.env.URL && process.env.URL.includes('localhost');
/**
* Default load state to be used while loading a URL or performing a click and navigate operation.
* The load state is set to 'domcontentloaded', which means the action will wait until the 'DOMContentLoaded' event is fired.
*/
export const LOADSTATE: WaitForLoadStateOptions = 'domcontentloaded';
export default defineConfig({
/**
* The directory where tests are located.
* See https://playwright.dev/docs/api/class-testconfig#testconfig-testdir
*/
testDir: './tests',
/**
* Determines whether to run tests within each spec file in parallel, in addition to running the spec files themselves in parallel.
* See https://playwright.dev/docs/api/class-testconfig#testconfig-fullyparallel
*/
fullyParallel: false,
/**
* Whether to fail the build on CI if you accidentally left test.only in the source code.
* See https://playwright.dev/docs/api/class-testconfig#testconfig-forbidonly
*/
forbidOnly: !!process.env.CI,
/**
* The number of times to retry failed tests. Retries value is only set to happen on CI.
* See https://playwright.dev/docs/api/class-testconfig#testconfig-retries
*/
retries: process.env.CI ? 2 : 0,
/**
* The number of worker threads to use for running tests. This is set to a different value on CI.
* See https://playwright.dev/docs/api/class-testconfig#testconfig-workers
*/
workers: process.env.CI ? 3 : 6,
/* Note: Add allure-playwright report */
/**
* The reporter to use. This can be set to use a different value on CI.
* See https://playwright.dev/docs/test-reporters
*/
reporter: [['./src/vasu-playwright/setup/custom-logger.ts'], ['html', { open: 'never' }], ['dot']],
/**
* Shared settings for all the projects below.
* See https://playwright.dev/docs/api/class-testoptions
*/
globalSetup: require.resolve('./src/vasu-playwright/setup/global-setup.ts'),
globalTeardown: require.resolve('./src/vasu-playwright/setup/global-teardown.ts'),
timeout: TEST_TIMEOUT,
expect: {
timeout: EXPECT_TIMEOUT,
},
use: {
headless: true,
/* Sets extra headers for CloudFlare. */
extraHTTPHeaders: {
'CF-Access-Client-Id': process.env.CF_CLIENT_ID || '',
'CF-Access-Client-Secret': process.env.CF_CLIENT_SECRET || '',
},
ignoreHTTPSErrors: true,
acceptDownloads: true,
testIdAttribute: 'qa-target',
/**
* The base URL to be used in navigation actions such as `await page.goto('/')`.
* This allows for shorter and more readable navigation commands in the tests.
*/
baseURL: BASE_URL,
/* Records traces after each test failure for debugging purposes. */
trace: 'retain-on-failure',
/* Captures screenshots after each test failure to provide visual context. */
screenshot: 'only-on-failure',
/* Sets a timeout for actions like click, fill, select to prevent long-running operations. */
actionTimeout: ACTION_TIMEOUT,
/* Sets a timeout for page loading navigations like goto URL, go back, reload, waitForNavigation to prevent long page loads. */
navigationTimeout: NAVIGATION_TIMEOUT,
},
/**
* Configure projects for major browsers.
* See https://playwright.dev/docs/test-configuration#projects
*/
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
viewport: { width: 1600, height: 1000 },
launchOptions: {
args: ['--disable-web-security'],
/* --auto-open-devtools-for-tabs option is used to open a test with Network tab for debugging. It can help in analyzing network requests and responses.*/
// args: ["--disable-web-security","--auto-open-devtools-for-tabs"],
slowMo: 0,
},
},
},
/******* Uncomment to run tests in other browsers
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
viewport: { width: 1600, height: 1000 },
launchOptions: {
firefoxUserPrefs: {
'browser.cache.disk.enable': false,
'browser.cache.memory.enable': false,
},
},
},
},
{
name: 'webkit',
use: {
...devices['Desktop Safari'],
viewport: { width: 1600, height: 1000 },
},
},
// Test against mobile viewports.
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] },
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
},
// Test against branded browsers.
{
name: 'Microsoft Edge',
use: { ...devices['Desktop Edge'], channel: 'msedge' },
},
{
name: 'Google Chrome',
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
},
***************/
],
/**
* If the tests are being run on localhost, this configuration starts a web server.
* See https://playwright.dev/docs/test-configuration#webserver
*/
...(startLocalHost && {
webServer: {
command: 'cd ~/repos/ui && npm start ui-server',
port: 9002,
timeout: 60 * 1000,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
},
}),
});