-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathBrowserStackSampleLocal.js
More file actions
85 lines (76 loc) · 2.77 KB
/
BrowserStackSampleLocal.js
File metadata and controls
85 lines (76 loc) · 2.77 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
let wd = require('wd');
let assert = require('assert');
let asserters = wd.asserters;
let Q = wd.Q;
let browserstack = require('browserstack-local');
// Set your BrowserStack access credentials
let userName = 'YOUR_USERNAME'
let accessKey = "YOUR_ACCESS_KEY"
desiredCaps = {
'browserstack.user' : userName,
'browserstack.key' : accessKey,
// Set URL of the application under test
'app' : 'bs://<app-id>',
// Specify device and os_version for testing
'device' : 'Google Pixel 3',
'os_version' : '9.0',
//Set browserstack.local capability as true
'browserstack.local' : true,
// Set other BrowserStack capabilities
'project' : 'First NodeJS project',
'build' : 'browserstack-build-1',
'name': 'local_test',
'browserstack.debug' : true,
};
let promise = new Promise(function(resolve, reject) {
// Start BrowserStack Local
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': accessKey}, (error) => {
if (error) return reject(error);
console.log('BrowserStack Local connected.');
resolve();
});
});
promise.then(function() {
// Initialize the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
driver = wd.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
// Test case for the BrowserStack sample Android Local app.
// If you have uploaded your app, update the test case here.
driver.init(desiredCaps)
.then(function () {
return driver.waitForElementById('com.example.android.basicnetworking:id/test_action', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (testElement) {
return testElement.click();
})
.then(function () {
return driver.waitForElementsByClassName('android.widget.TextView', asserters.isDisplayed, 30000);
})
.then(function (textElements) {
return Q().then(function () {
return textElements.map(function (textElement) {
return textElement.text().then(function(value) {
if (value.indexOf('The active connection is') !== -1) {
console.log(value);
assert(value.indexOf('The active connection is wifi') !== -1);
assert(value.indexOf('Up and running') !== -1);
}
});
})
}).all()
})
.fin(function() {
// Invoke driver.quit() after the test is done to indicate that the test is completed.
return driver.quit();
})
.done(function() {
// Stop BrowserStack Local
exports.bs_local.stop((error) => {
if(error) return console.log("Error in stopping BrowserStack Local :"+ error)
console.log("Stopped BrowserStack Local")
})
});
}, function(error) {
console.log("Failed to start BrowserStack Local :" + error)
})