Skip to content

Commit 80033fc

Browse files
authored
Merge pull request #1 from browserstack/app_automate_tests
Add App Automate tests
2 parents 0dec78d + 79c53b5 commit 80033fc

File tree

7 files changed

+254
-0
lines changed

7 files changed

+254
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# node-appium-app-browserstack
2+
App Automate Node Samples
3+
---------------------
4+
5+
This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.
6+
7+
For frameworks integration with BrowserStack, refer to their individual repositories -
8+
9+
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)

android/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
For installing the node `wd` driver,
3+
4+
```
5+
$ npm install wd
6+
```
7+
8+
## Running your tests
9+
10+
- Do remember to switch the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your own browserstack credentials.
11+
- Upload your Native App (.apk file) to BrowserStack servers using upload API and update the app capability:
12+
13+
```
14+
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk"
15+
```
16+
17+
- If you do not have an .apk file and looking to simply try App Automate, you can download our [sample app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) and upload to the BrowserStack servers using the above API.
18+
- For LocalSample tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk).
19+
- Update the desired capability "app" with the App URL returned from the above API call
20+
21+
## Notes
22+
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
23+
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-node) document to configure the capabilities
24+
25+
For frameworks integration with BrowserStack, refer to their individual repositories -
26+
27+
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)

android/localTest.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var wd = require('wd');
2+
var assert = require('assert');
3+
var asserters = wd.asserters;
4+
var Q = wd.Q;
5+
6+
desiredCaps = {
7+
'browserstack.user' : 'BROWSERSTACK_USERNAME',
8+
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
9+
'build' : 'Node Android',
10+
'name': 'local_test',
11+
'device' : 'Google Pixel',
12+
'app' : 'bs://<hashed app-id>',
13+
'browserstack.debug' : true,
14+
'browserstack.local' : true,
15+
'realMobile' : true
16+
};
17+
18+
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");
19+
20+
driver
21+
.init(desiredCaps)
22+
.then(function () {
23+
return driver.waitForElementById('com.example.android.basicnetworking:id/test_action', asserters.isDisplayed && asserters.isEnabled, 30000);
24+
})
25+
.then(function (testElement) {
26+
return testElement.click();
27+
})
28+
.then(function () {
29+
return driver.waitForElementsByClassName('android.widget.TextView', asserters.isDisplayed, 30000);
30+
})
31+
.then(function (textElements) {
32+
return Q().then(function () {
33+
return textElements.map(function (textElement) {
34+
return textElement.text().then(function(value) {
35+
if (value.indexOf('The active connection is') !== -1) {
36+
console.log(value);
37+
assert(value.indexOf('The active connection is wifi') !== -1);
38+
assert(value.indexOf('Up and running') !== -1);
39+
}
40+
});
41+
})
42+
}).all()
43+
})
44+
.fin(function() { return driver.quit(); })
45+
.done();

android/singleTest.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var wd = require('wd');
2+
var assert = require('assert');
3+
var asserters = wd.asserters;
4+
5+
desiredCaps = {
6+
'browserstack.user' : 'BROWSERSTACK_USERNAME',
7+
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
8+
'build' : 'Node Android',
9+
'name': 'single_test',
10+
'device' : 'Google Pixel',
11+
'app' : 'bs://<hashed app-id>',
12+
'browserstack.debug' : true,
13+
'realMobile' : true
14+
};
15+
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");
16+
17+
driver
18+
.init(desiredCaps)
19+
.then(function () {
20+
return driver.waitForElementById('Search Wikipedia', asserters.isDisplayed && asserters.isEnabled, 30000);
21+
})
22+
.then(function (searchElement) {
23+
return searchElement.click();
24+
})
25+
.then(function () {
26+
return driver.waitForElementById('org.wikipedia.alpha:id/search_src_text', asserters.isDisplayed && asserters.isEnabled, 30000);
27+
})
28+
.then(function (searchInput) {
29+
return searchInput.sendKeys("BrowserStack");
30+
})
31+
.then(function () {
32+
return driver.elementsByClassName('android.widget.TextView');
33+
})
34+
.then(function (search_results) {
35+
assert(search_results.length > 0);
36+
})
37+
.fin(function() { return driver.quit(); })
38+
.done();

ios/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
For installing the node `wd` driver,
3+
4+
```
5+
$ npm install wd
6+
```
7+
8+
## Running your tests
9+
10+
- Do remember to switch the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your own browserstack credentials.
11+
- Upload your Native App (.ipa file) to BrowserStack servers using upload API and update the app capability:
12+
13+
```
14+
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa"
15+
```
16+
17+
- If you do not have an .ipa file and looking to simply try App Automate, you can download our [sample app](https://www.browserstack.com/app-automate/sample-apps/ios/WordPressSample.ipa) and upload to the BrowserStack servers using the above API.
18+
- For LocalSample tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
19+
- Update the desired capability "app" with the App URL returned from the above API call
20+
21+
## Notes
22+
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
23+
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-node) document to configure the capabilities
24+
25+
For frameworks integration with BrowserStack, refer to their individual repositories -
26+
27+
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)

ios/localTest.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var wd = require('wd');
2+
var assert = require('assert');
3+
var asserters = wd.asserters;
4+
var Asserter = wd.Asserter;
5+
6+
var chai = require("chai");
7+
var chaiAsPromised = require("chai-as-promised");
8+
chai.use(chaiAsPromised);
9+
chai.should();
10+
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
11+
12+
desiredCaps = {
13+
'browserstack.user' : 'BROWSERSTACK_USERNAME',
14+
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
15+
'build' : 'Node iOS',
16+
'name': 'local_test',
17+
'device' : 'iPhone 7 Plus',
18+
'app' : 'bs://<hashed app-id>',
19+
'browserstack.debug' : true,
20+
'browserstack.local' : true,
21+
'realMobile' : true
22+
};
23+
24+
var customTextNonEmpty = new Asserter(
25+
function(target) {
26+
return target
27+
.text().then(function(text) {
28+
text.should.have.length.above(0);
29+
return text;
30+
})
31+
.catch(tagChaiAssertionError);
32+
}
33+
);
34+
35+
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");
36+
37+
driver
38+
.init(desiredCaps)
39+
.then(function () {
40+
return driver.waitForElementById('TestBrowserStackLocal', asserters.isDisplayed && asserters.isEnabled, 30000);
41+
})
42+
.then(function (testElement) {
43+
return testElement.click();
44+
})
45+
.then(function () {
46+
return driver.waitForElementById('ResultBrowserStackLocal', asserters.isDisplayed, 30000);
47+
})
48+
.then(function (resultElement) {
49+
return resultElement.text().should.eventually.include('Up and running');
50+
})
51+
.fin(function() { return driver.quit(); })
52+
.done();

ios/singleTest.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var wd = require('wd');
2+
var assert = require('assert');
3+
var asserters = wd.asserters;
4+
var sleep = require('sleep');
5+
var Q = wd.Q;
6+
7+
desiredCaps = {
8+
'browserstack.user' : 'BROWSERSTACK_USERNAME',
9+
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
10+
'build' : 'Node iOS',
11+
'name': 'single_test',
12+
'device' : 'iPhone 7 Plus',
13+
'app' : 'bs://<hashed app-id>',
14+
'browserstack.debug' : true,
15+
'realMobile' : true
16+
};
17+
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");
18+
19+
driver
20+
.init(desiredCaps)
21+
.then(function () {
22+
return driver.waitForElementById('Log In', asserters.isDisplayed && asserters.isEnabled, 30000);
23+
})
24+
.then(function (loginButton) {
25+
return loginButton.click();
26+
})
27+
.then(function () {
28+
return driver.waitForElementById('Email address', asserters.isDisplayed && asserters.isEnabled, 30000);
29+
})
30+
.then(function (emailInput) {
31+
return emailInput.sendKeys("[email protected]");
32+
})
33+
.then(function () {
34+
return driver.waitForElementById('Next', asserters.isDisplayed, 30000);
35+
})
36+
.then(function (nextButton) {
37+
return nextButton.click().then(function() {
38+
sleep.sleep(5);
39+
});
40+
})
41+
.then(function() {
42+
return driver.waitForElementsByXPath("//XCUIElementTypeStaticText", asserters.isDisplayed, 30000);
43+
})
44+
.then(function (textElements) {
45+
return Q().then(function () {
46+
return textElements.map(function (textElement) {
47+
return textElement.text().then(function(value) {
48+
if (value.indexOf('not registered') !== -1) {
49+
console.log(value);
50+
assert(value.indexOf('This email address is not registered on WordPress.com') !== -1);
51+
}
52+
});
53+
})
54+
}).all()
55+
})
56+
.fin(function() { return driver.quit(); })
57+
.done();

0 commit comments

Comments
 (0)