-
Notifications
You must be signed in to change notification settings - Fork 5
/
playwright.config.ts
204 lines (192 loc) · 6.89 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* 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 'vasu-playwright-utils';
import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
import path from 'path';
import os from 'os';
/**
* To run against the local environment, set the URL to your local server like 'https://localhost:9002'
* You can override the BASE_URL by setting the URL environment variable in .env file or passing it as a command line argument.
*/
export const BASE_URL = process.env.URL || 'https://www.saucedemo.com';
export const STORAGE_STATE_PATH = path.join(__dirname, 'playwright/.auth');
const customLoggerPath = require.resolve('vasu-playwright-utils/custom-logger');
// export const EMPTY_STORAGE_STATE = path.join(__dirname, './tests/testdata/empty-storage-state.json');
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: [[customLoggerPath], ['html', { open: 'never' }], ['dot']],
/**
* Shared settings for all the projects below.
* See https://playwright.dev/docs/api/class-testoptions
*/
globalSetup: require.resolve('./test-setup/global-setup'),
globalTeardown: require.resolve('./test-setup/global-teardown'),
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,
// Set the testIdAttribute for locating elements in the tests with getLocatorByTestId. Default is 'data-testid'.
// 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: 'setup',
testMatch: '**/login-storage-setup.ts',
use: {
...devices['Desktop Chrome'],
viewport: { width: 1600, height: 1000 },
launchOptions: {
args: ['--disable-web-security'],
slowMo: 0,
},
},
},
/** Due to different view ports in Head and Headless, created 2 projects one for head mode and the same browser for headless. */
{
name: 'chromium',
dependencies: ['setup'],
use: {
viewport: null,
// Set the storage state here if you have only one user to login.
// storageState: STORAGE_STATE_LOGIN,
launchOptions: {
args: ['--disable-web-security', '--start-maximized'],
/* --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: ["--auto-open-devtools-for-tabs"],
// channel: 'chrome',
slowMo: 0,
headless: false,
},
},
},
{
name: 'chromiumheadless',
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
viewport: { width: 1600, height: 1000 },
// storageState: STORAGE_STATE_LOGIN,
launchOptions: {
args: ['--disable-web-security'],
// channel: 'chrome',
slowMo: 0,
headless: true,
},
},
},
/******* 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-webserver#configuring-a-web-server
*/
webServer: {
cwd: `${os.homedir()}/repos/ui`, // You can also use the relative path to the UI repo
command: 'npm start ui-server', // Start the UI server
url: BASE_URL,
ignoreHTTPSErrors: true,
timeout: 2 * 60 * 1000,
reuseExistingServer: true,
stdout: 'pipe',
stderr: 'pipe',
},
});