-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaywright.config.js
194 lines (171 loc) · 6.32 KB
/
playwright.config.js
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
// @ts-check
const { defineConfig, devices } = require('@playwright/test');
const { resolve } = require('path');
const fs = require('fs');
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
require('dotenv').config();
const { REPORT_FOLDER, CICD } = process.env;
const ts = REPORT_FOLDER ?? +new Date;
const testDir = resolve(__dirname, '__tests__/e2e');
const reportDir = resolve(__dirname, '__report__');
const outputFolder = `${reportDir}/e2e/${ts}`;
/**
* @description Move old reports to archive.
* @constant
* @return {boolean}
*/
const handleLogsRotation = () => {
const _path = `${reportDir}/e2e`;
const _archive = `${reportDir}/e2e/archive`;
// Prevent log rotation on GitHub.
if (CICD === '1') return false;
if (_path.match(/archive/)) return false;
if (!fs.existsSync(_archive)) {
fs.mkdirSync(_archive);
}
fs.readdirSync(_path).forEach(folder => {
if (folder.match(/archive/)) return false;
let _ts = '';
if (folder === REPORT_FOLDER) {
_ts = `-${+new Date}`;
}
fs.rename(`${_path}/${folder}`, `${_archive}/${folder}${_ts}`, (err) => {
if (err) throw err;
console.log(`Successfully moved: ${_archive}/${folder}`);
});
});
};
handleLogsRotation();
global.sPath = `${outputFolder}/screenshots`;
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: `${testDir}/specs`,
outputDir: `${outputFolder}/errors`,
// snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
['list'],
['html', { outputFolder: `${outputFolder}/html` }],
['junit', { outputFile: `${outputFolder}/logs/junit/results.xml` }],
['json', { outputFile: `${outputFolder}/logs/json/test-results.json` }]
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
ignoreHTTPSErrors: true,
bypassCSP: true,
screenshot: 'only-on-failure',
timeout: 10 * 60 * 1000
// proxy: {
// server: 'http://genproxy:8080'
// }
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
// headless: false,
launchOptions: {
// prefs: {
// credentials_enable_service: false,
// profile: {
// password_manager_enabled: false
// },
// download: {
// prompt_for_download: false,
// directory_upgrade: true,
// default_directory: path.join(__dirname, 'downloads')
// }
// },
args: [
// Authentication Popups: https://www.lambdatest.com/blog/handle-alerts-popups-in-selenium-protractor/
// The key usage of authentication popups is to authenticate user access. These popups are generally observed in password-protected pages and consist of a username and password dialogue boxes.
// An authentication popup can be identified by the following characteristics:
// - The elements of the authentication pop-up overlay cannot be inspected by the user.
// - This pop-up is displayed on the occurrence of the loading of the web-page.
// - The page can only be accessed through the input of valid credentials.
// - The pop-up may or may not be movable as per the browser configuration.
// - The UI of the pop-up is highly customizable.
// - The solution to handle this type of alert in selenium is to enter valid credentials along with the URL. The syntax for password and username in authentication pop-ups are:
//
// driver.get(protocol://Usename:Password@URL Address);
//'--incognito',
// '--disable-cache',
// '--disable-web-security',
// '--disable-application-cache',
// '--disable-offline-load-stale-cache',
// '--disk-cache-size=0',
// '--v8-cache-options=off',
// '--no-sandbox',
// '--test-type=browser',
// Without a remote debugging port, Google Chrome exits immediately.
// '--remote-debugging-port=9222',
// '--test-type',
// '--disable-web-security',
'--allow-insecure-localhost',
'--ignore-certificate-errors'
// '--proxy-server=http://genproxy:8080'
// '--disable-machine-cert-request',
// '--ignore-certificate-errors-spki-list',
// '--ignore-urlfetcher-cert-requests'
// '--allow-running-insecure-content',
// '--disable-proxy-certificate-handler',
// '--disable-content-security-policy',
// '--ignore-certificate-errors-spki-list=jc7r1tE54FOO=',
// '--log-path=chromedriver.log'
]
}
}
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
}
/* 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' },
// },
]
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});