This repository was archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (76 loc) · 2.66 KB
/
index.js
File metadata and controls
92 lines (76 loc) · 2.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
const browserstack = require('browserstack-local')
const webdriver = require('selenium-webdriver')
const path = require('path')
const { startServer, stopServer } = require('./server')
const { BROWSERSTACK_KEY, BROWSERSTACK_USER } = require('./browserstack.config')
// creates an instance of Local
const bsLocal = new browserstack.Local()
const LOCAL_IDENTIFIER = 'ladgfjöadfglij'
if (BROWSERSTACK_KEY === '<put your browserstack key here>') {
throw 'You need to edit your browserstack user & key in `browserstack.config.js`!'
}
const bsLocalArgs = {
key: BROWSERSTACK_KEY,
verbose: true,
force: true,
forceLocal: true,
local: true,
f: path.resolve(__dirname, './localFolder'),
localIdentifier: LOCAL_IDENTIFIER,
// localProxyHost: '127.0.0.1',
// localProxyPort: '3128',
// proxyUser: 'user',
// proxyPass: 'password',
}
startServer()
// starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs, async (error) => {
if (error) {
throw error
}
console.log('Started BrowserStackLocal')
// Input capabilities
const capabilities = {
browserName: 'Chrome',
browser_version: '62.0',
os: 'Windows',
os_version: '10',
resolution: '1024x768',
'browserstack.user': BROWSERSTACK_USER,
'browserstack.key': BROWSERSTACK_KEY,
'browserstack.localIdentifier' : LOCAL_IDENTIFIER,
}
const driver = new webdriver.Builder()
.usingServer('http://hub-cloud.browserstack.com/wd/hub')
.withCapabilities(capabilities)
.build()
console.log('Built driver')
try {
const navigateAndCheckTitle = async (url, expectedTitle) => {
console.log(`Navigating to ${url}`)
await driver.get(url)
const title = await driver.getTitle()
if (title == expectedTitle) {
console.log(`> SUCCESS loading ${url}`)
} else {
console.log(`> ERROR loading ${url}: expected title "${expectedTitle}", found "${title}"`)
}
}
// navigate to a public url
await navigateAndCheckTitle('https://usersnap.com', 'Usersnap – Smart Feedback to Build Great Digital Products')
// navigate to a local url
await navigateAndCheckTitle('http://localhost:3000', 'Hello world from server!')
await navigateAndCheckTitle('http://127.0.0.1:3000', 'Hello world from server!')
// navigate to the folder referenced in `bsLocalArgs`
await navigateAndCheckTitle(`http://${BROWSERSTACK_USER}.browserstack.com/index.html`, 'Hello world from local folder!')
} finally {
driver.quit().then(() => {
console.log('Quit driver')
// stop the Local instance
bsLocal.stop(() => {
stopServer()
console.log('Stopped BrowserStackLocal')
})
})
}
})