-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
browserstack.node.js
81 lines (77 loc) · 2.46 KB
/
browserstack.node.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
// npm install --no-save selenium-webdriver
// touch browserstackCreds.json
// open https://automate.browserstack.com/dashboard/v2/
const webdriver = require("selenium-webdriver")
const { userName, accessKey } = require("../ignore/browserstackCreds.json")
const { version } = require("../package.json")
const browserstackURL = "https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub"
const homePageUrl = "https://scroll.pub"
async function runTestWithCaps(capabilities) {
try {
let driver = new webdriver.Builder()
.usingServer(`http://${userName}:${accessKey}@hub-cloud.browserstack.com/wd/hub`)
.withCapabilities(capabilities)
.build()
await driver.get(homePageUrl)
try {
await driver.wait(webdriver.until.titleMatches(/Scroll/i), 5000)
const title = await driver.getTitle()
const message = `${title} v${version} loaded on ${capabilities.browserName} on ${capabilities.device ?? capabilities.os}`
console.log(message)
await driver.executeScript(`browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "${message}"}}`)
} catch (err) {
console.error(err)
await driver.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Page could not load in time"}}')
}
await driver.quit()
} catch (err) {
console.error(err)
}
}
const build = `Scroll v${version}`
const capabilities1 = {
browserName: "chrome",
browser_version: "latest",
os: "Windows",
os_version: "10",
build,
name: "Parallel test 1"
}
const capabilities2 = {
browserName: "firefox",
browser_version: "latest-beta",
os: "Windows",
os_version: "10",
build,
name: "Parallel test 2"
}
const capabilities3 = {
device: "iPhone 12 Pro",
browserName: "iPhone",
os_version: "14",
real_mobile: "true",
build,
name: "Parallel test 3"
}
const capabilities4 = {
device: "Samsung Galaxy S21",
browserName: "Android",
os_version: "11.0",
real_mobile: "true",
build,
name: "Parallel test 4"
}
const capabilities5 = {
browserName: "Safari",
browser_version: "latest",
os: "OS X",
os_version: "Big Sur",
build,
name: "Parallel test 5"
}
// The following code invokes the test function 5 times in parallel with separate capabilities as defined above
runTestWithCaps(capabilities1)
runTestWithCaps(capabilities2)
runTestWithCaps(capabilities3)
runTestWithCaps(capabilities4)
runTestWithCaps(capabilities5)