-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.js
More file actions
108 lines (93 loc) · 3.66 KB
/
Copy pathsetup.js
File metadata and controls
108 lines (93 loc) · 3.66 KB
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
const { setWorldConstructor, World, Before, After, Status, setDefaultTimeout } = require("@cucumber/cucumber");
const { chromium, devices } = require('playwright');
const cp = require('child_process');
const BrowserStackLocal = require('browserstack-local');
const playwrightClientVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];
setDefaultTimeout(120 * 1000);
const enableLocalTesting = false; // Set this flag to true to enable BrowserStack Local testing
const browserConfigs = [
{
browserName: 'chrome',
browserTagName: '@chrome',
browserVersion: 'latest',
os: 'OS X',
osVersion: 'Monterey',
resolution: '1280x1024',
},
{
browserName: 'playwright-firefox',
browserTagName: '@playwright-firefox',
browserVersion: 'latest',
os: 'Windows',
osVersion: '11',
resolution: '1280x1024',
},
{
browserName: 'edge',
browserTagName: '@edge',
browserVersion: 'latest',
os: 'OS X',
osVersion: 'Ventura',
resolution: '1280x1024',
},
];
const browserConnections = [];
Before(async (scenario) => {
const tagName = scenario.pickle.tags[0].name;
const filteredBrowserConfigs = browserConfigs.filter(config => config.browserTagName === tagName);
for (const browserConfig of filteredBrowserConfigs) {
const caps = {
...browserConfig,
'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
'project': 'PLAYWRIGHT-CUCUMBER-JS',
'build': 'playwright-cucumber-build-1',
'name': scenario.pickle.name,
'buildTag': 'Regression',
'browserstack.playwrightVersion': '1.latest',
'client.playwrightVersion': '1.latest'
};
console.log('enableLocalTesting', enableLocalTesting);
if (enableLocalTesting && browserConnections.length === 0) {
const bsLocal = new BrowserStackLocal.Local();
const bsLocalArgs = {
key: process.env.BROWSERSTACK_ACCESS_KEY, // Replace with your BrowserStack access key
localIdentifier: 'local_connection_name' // Replace with your desired local connection name
};
await new Promise((resolve, reject) => {
bsLocal.start(bsLocalArgs, (error) => {
if (error) {
console.error('Failed to start BrowserStack Local:', error);
reject(error);
} else {
console.log('BrowserStack Local started successfully');
resolve();
}
});
});
}
// Create page and browser globals to be used in the scenarios
const browser = await chromium.connect({
wsEndpoint: `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`,
});
const context = await browser.newContext();
global.page = await context.newPage();
browserConnections.push(browser);
}
});
After(async () => {
await Promise.all(browserConnections.map(browser => browser.close()));
});
After(async (scenario) => {
if (scenario.result.status === Status.PASSED) {
await page.evaluate(_ => { }, `browserstack_executor: ${JSON.stringify({ action: 'setSessionStatus', arguments: { status: 'passed', reason: 'Test Passed' } })}`);
} else if (scenario.result.status === Status.FAILED) {
await page.evaluate(_ => { }, `browserstack_executor: ${JSON.stringify({ action: 'setSessionStatus', arguments: { status: 'failed', reason: 'Test Failed' } })}`);
}
});
setWorldConstructor(function () {
this.testCaseRetry = 2; // Set the number of retries for each test case
});
module.exports = {
parallel: 2, // Set the number of parallel test workers to the number of browsers
};