-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserstack.config.js
70 lines (62 loc) · 2.26 KB
/
browserstack.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
require('dotenv').config();
const cp = require('child_process');
const clientPlaywrightVersion = cp
.execSync('npx playwright --version')
.toString()
.trim()
.split(' ')[1];
const BrowserStackLocal = require('browserstack-local');
// BrowserStack Specific Capabilities
const caps = {
name: 'my playwright test',
build: 'localhost-5',
'browserstack.username': process.env.BROWSERSTACK_USERNAME,
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY,
'browserstack.local': !!process.env.PW_URL.includes('localhost'),
// "browserstack.idleTimeout" : "300",
'browserstack.playwrightVersion': clientPlaywrightVersion,
'bstack:options': {
timezone: 'London'
}
};
exports.patchMobileCaps = (name, title) => {
const combination = name.split(/@browserstack/)[0];
const [browerCaps, osCaps] = combination.split(/:/);
const [browser, deviceName] = browerCaps.split(/@/);
const osCapsSplit = osCaps.split(/ /);
const osVersion = osCapsSplit.join(' ');
caps.browser = browser || 'chrome';
caps.deviceName = deviceName || 'Samsung Galaxy S22 Ultra';
caps.osVersion = osVersion || '12.0';
caps.name = title;
caps.realMobile = 'true';
// 'bstack:options' = {
// "timezone" : "London",
// }
};
exports.caps = caps;
exports.bsLocal = new BrowserStackLocal.Local();
exports.BS_LOCAL_ARGS = {
key: process.env.BROWSERSTACK_ACCESS_KEY
};
// Patching the capabilities dynamically according to the project name.
exports.patchCaps = (name, title) => {
const combination = name.split(/@browserstack/)[0];
const [browerCaps, osCaps] = combination.split(/:/);
const [browser, browser_version] = browerCaps.split(/@/);
const osCapsSplit = osCaps.split(/ /);
const os = osCapsSplit.shift();
const os_version = osCapsSplit.join(' ');
caps.browser = browser || 'chrome';
caps.browser_version = browser_version || 'latest';
caps.os = os || 'osx';
caps.os_version = os_version || 'catalina';
caps.name = name;
caps.title = title;
caps.firefox_user_prefs = { 'dom.events.asyncClipboard.readText': true, 'dom.events.testing.asyncClipboard': true };
};
exports.getCdpEndpoint = (name, title) => {
patchCaps(name, title);
const cdpUrl = `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`;
return cdpUrl;
};