-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathBrowserStackSampleLocal.js
More file actions
86 lines (79 loc) · 2.86 KB
/
BrowserStackSampleLocal.js
File metadata and controls
86 lines (79 loc) · 2.86 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
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 = {
"forceW3C": true,
// Specify device and os_version for testing
"platformName": "Android",
"appium:platformVersion": "9.0",
"appium:deviceName": 'Google Pixel 3',
// Set URL of the application under test
"appium:app": 'bs://<app-id>',
// Set other BrowserStack capabilities
'bstack:options' : {
"projectName" : "First NodeJS Android Project",
"buildName" : "browserstack-build-1",
"sessionName" : "BStack local_test",
"debug" : "true",
"local" : "true",
"userName" : userName,
"accessKey" : accessKey
}
};
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.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)
})