Skip to content

Commit af5fe14

Browse files
authored
Merge pull request #8 from kn-neeraj/qsg-firsttest-changes
Update first test script according to QSG spec and added package.json to manage npm dependencies
2 parents 123fd6d + 17ffd6c commit af5fe14

16 files changed

+1318
-234
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,105 @@
11
# node-appium-app-browserstack
2-
App Automate Node Samples
3-
---------------------
42

5-
This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.
3+
This repository demonstrates how to run Appium NodeJS tests on BrowserStack App Automate.
64

7-
For frameworks integration with BrowserStack, refer to their individual repositories -
5+
## Setup
6+
7+
### Requirements
8+
9+
1. Node.js
10+
11+
- If not installed, install Node.js from [here](https://nodejs.org/en/download/)
12+
13+
- Ensure you have node & npm installed by running `node -v` & `npm -v`
14+
15+
### Install the dependencies
16+
17+
To install the dependencies run the following command in the project's base directory :
18+
19+
```
20+
npm install
21+
```
22+
23+
## Getting Started
24+
25+
Getting Started with Appium tests in NodeJS on BrowserStack couldn't be easier!
26+
27+
### Run your first test :
28+
29+
**1. Upoad your Android or iOS App**
30+
31+
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request :
32+
33+
```
34+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
35+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
36+
-F "file=@/path/to/apk/file"
37+
```
38+
39+
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
40+
41+
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa).
42+
43+
**2. Configure and run your first test**
44+
45+
Open `BrowserStackSample.js` file in `Android` or in `ios` folder
46+
47+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
48+
49+
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
50+
51+
- Set the device and OS version
52+
53+
- If you have uploaded your own app update the test case
54+
55+
- Run `node BrowserStackSample.js`
56+
57+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
58+
59+
---
60+
61+
### **Use Local testing for apps that access resources hosted in development or testing environments :**
62+
63+
**1. Upload your Android or iOS App**
64+
65+
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request :
66+
67+
```
68+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
69+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
70+
-F "file=@/path/to/apk/file"
71+
```
72+
73+
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
74+
75+
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
76+
77+
**2. Configure and run your local tes**
78+
79+
Open `BrowserStackSampleLocal.js` file in `Android` or in `ios` folder
80+
81+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
82+
83+
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
84+
85+
- Set the device and OS version
86+
87+
- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Javascript binding for BrowserStack Local.
88+
89+
- If you have uploaded your own app update the test case
90+
91+
- Run `node BrowserStackSampleLocal.js`
92+
93+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
94+
95+
## Integration with other NodeJS frameworks
96+
97+
For other NodeJS frameworks samples, refer to following repositories :
898

999
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
100+
101+
Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)
102+
103+
## Getting Help
104+
105+
If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help).

android/.DS_Store

6 KB
Binary file not shown.

android/BrowserStackSample.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
let wd = require('wd');
2+
let assert = require('assert');
3+
let asserters = wd.asserters;
4+
5+
desiredCaps = {
6+
// Set your BrowserStack access credentials
7+
'browserstack.user' : 'YOUR_USERNAME',
8+
'browserstack.key' : 'YOUR_ACCESS_KEY',
9+
10+
// Set URL of the application under test
11+
'app' : 'bs://<app-id>',
12+
13+
// Specify device and os_version for testing
14+
'device' : 'Google Pixel 3',
15+
'os_version' : '9.0',
16+
17+
// Set other BrowserStack capabilities
18+
'project' : 'First NodeJS project',
19+
'build' : 'Node Android',
20+
'name': 'first_test'
21+
};
22+
23+
// Initialize the remote Webdriver using BrowserStack remote URL
24+
// and desired capabilities defined above
25+
driver = wd.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
26+
27+
// Test case for the BrowserStack sample Android app.
28+
// If you have uploaded your app, update the test case here.
29+
driver.init(desiredCaps)
30+
.then(function () {
31+
return driver.waitForElementByAccessibilityId(
32+
'Search Wikipedia', asserters.isDisplayed
33+
&& asserters.isEnabled, 30000);
34+
})
35+
.then(function (searchElement) {
36+
return searchElement.click();
37+
})
38+
.then(function () {
39+
return driver.waitForElementById(
40+
'org.wikipedia.alpha:id/search_src_text', asserters.isDisplayed
41+
&& asserters.isEnabled, 30000);
42+
})
43+
.then(function (searchInput) {
44+
return searchInput.sendKeys("BrowserStack");
45+
})
46+
.then(function () {
47+
return driver.elementsByClassName('android.widget.TextView');
48+
})
49+
.then(function (search_results) {
50+
assert(search_results.length > 0);
51+
})
52+
.fin(function() {
53+
// Invoke driver.quit() after the test is done to indicate that the test is completed.
54+
return driver.quit();
55+
})
56+
.done();

android/BrowserStackSampleLocal.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
let wd = require('wd');
2+
let assert = require('assert');
3+
let asserters = wd.asserters;
4+
let Q = wd.Q;
5+
let browserstack = require('browserstack-local');
6+
7+
// Set your BrowserStack access credentials
8+
let userName = 'YOUR_USERNAME'
9+
let accessKey = "YOUR_ACCESS_KEY"
10+
11+
desiredCaps = {
12+
'browserstack.user' : userName,
13+
'browserstack.key' : accessKey,
14+
15+
// Set URL of the application under test
16+
'app' : 'bs://<app-id>',
17+
18+
// Specify device and os_version for testing
19+
'device' : 'Google Pixel 3',
20+
'os_version' : '9.0',
21+
22+
//Set browserstack.local capability as true
23+
'browserstack.local' : true,
24+
25+
// Set other BrowserStack capabilities
26+
'project' : 'First NodeJS project',
27+
'build' : 'Node Android Local',
28+
'name': 'local_test',
29+
'browserstack.debug' : true,
30+
};
31+
32+
let promise = new Promise(function(resolve, reject) {
33+
// Start BrowserStack Local
34+
exports.bs_local = new browserstack.Local();
35+
exports.bs_local.start({'key': accessKey}, (error) => {
36+
if (error) return reject(error);
37+
console.log('BrowserStack Local connected.');
38+
resolve();
39+
});
40+
});
41+
42+
promise.then(function() {
43+
// Initialize the remote Webdriver using BrowserStack remote URL
44+
// and desired capabilities defined above
45+
driver = wd.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
46+
47+
// Test case for the BrowserStack sample Android Local app.
48+
// If you have uploaded your app, update the test case here.
49+
driver.init(desiredCaps)
50+
.then(function () {
51+
return driver.waitForElementById('com.example.android.basicnetworking:id/test_action', asserters.isDisplayed && asserters.isEnabled, 30000);
52+
})
53+
.then(function (testElement) {
54+
return testElement.click();
55+
})
56+
.then(function () {
57+
return driver.waitForElementsByClassName('android.widget.TextView', asserters.isDisplayed, 30000);
58+
})
59+
.then(function (textElements) {
60+
return Q().then(function () {
61+
return textElements.map(function (textElement) {
62+
return textElement.text().then(function(value) {
63+
if (value.indexOf('The active connection is') !== -1) {
64+
console.log(value);
65+
assert(value.indexOf('The active connection is wifi') !== -1);
66+
assert(value.indexOf('Up and running') !== -1);
67+
}
68+
});
69+
})
70+
}).all()
71+
})
72+
.fin(function() {
73+
// Invoke driver.quit() after the test is done to indicate that the test is completed.
74+
return driver.quit();
75+
})
76+
.done(function() {
77+
// Stop BrowserStack Local
78+
exports.bs_local.stop((error) => {
79+
if(error) return console.log("Error in stopping BrowserStack Local :"+ error)
80+
console.log("Stopped BrowserStack Local")
81+
})
82+
});
83+
}, function(error) {
84+
console.log("Failed to start BrowserStack Local :" + error)
85+
})

android/README.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

android/localTest.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

android/singleTest.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)