Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# node-appium-app-browserstack
App Automate Node Samples
---------------------

This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.

For frameworks integration with BrowserStack, refer to their individual repositories -

- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
27 changes: 27 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

For installing the node `wd` driver,

```
$ npm install wd
```

## Running your tests

- Do remember to switch the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your own browserstack credentials.
- Upload your Native App (.apk file) to BrowserStack servers using upload API and update the app capability:

```
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk"
```

- 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.
- For LocalSample tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk).
- Update the desired capability "app" with the App URL returned from the above API call

## Notes
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-node) document to configure the capabilities

For frameworks integration with BrowserStack, refer to their individual repositories -

- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
45 changes: 45 additions & 0 deletions android/localTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var wd = require('wd');
var assert = require('assert');
var asserters = wd.asserters;
var Q = wd.Q;

desiredCaps = {
'browserstack.user' : 'BROWSERSTACK_USERNAME',
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
'build' : 'Node Android',
'name': 'local_test',
'device' : 'Google Pixel',
'app' : 'bs://<hashed app-id>',
'browserstack.debug' : true,
'browserstack.local' : true,
'realMobile' : true
};

driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");

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() { return driver.quit(); })
.done();
38 changes: 38 additions & 0 deletions android/singleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var wd = require('wd');
var assert = require('assert');
var asserters = wd.asserters;

desiredCaps = {
'browserstack.user' : 'BROWSERSTACK_USERNAME',
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
'build' : 'Node Android',
'name': 'single_test',
'device' : 'Google Pixel',
'app' : 'bs://<hashed app-id>',
'browserstack.debug' : true,
'realMobile' : true
};
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");

driver
.init(desiredCaps)
.then(function () {
return driver.waitForElementById('Search Wikipedia', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (searchElement) {
return searchElement.click();
})
.then(function () {
return driver.waitForElementById('org.wikipedia.alpha:id/search_src_text', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (searchInput) {
return searchInput.sendKeys("BrowserStack");
})
.then(function () {
return driver.elementsByClassName('android.widget.TextView');
})
.then(function (search_results) {
assert(search_results.length > 0);
})
.fin(function() { return driver.quit(); })
.done();
27 changes: 27 additions & 0 deletions ios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

For installing the node `wd` driver,

```
$ npm install wd
```

## Running your tests

- Do remember to switch the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your own browserstack credentials.
- Upload your Native App (.ipa file) to BrowserStack servers using upload API and update the app capability:

```
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa"
```

- 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.
- For LocalSample tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
- Update the desired capability "app" with the App URL returned from the above API call

## Notes
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-node) document to configure the capabilities

For frameworks integration with BrowserStack, refer to their individual repositories -

- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
52 changes: 52 additions & 0 deletions ios/localTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var wd = require('wd');
var assert = require('assert');
var asserters = wd.asserters;
var Asserter = wd.Asserter;

var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

desiredCaps = {
'browserstack.user' : 'BROWSERSTACK_USERNAME',
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
'build' : 'Node iOS',
'name': 'local_test',
'device' : 'iPhone 7 Plus',
'app' : 'bs://<hashed app-id>',
'browserstack.debug' : true,
'browserstack.local' : true,
'realMobile' : true
};

var customTextNonEmpty = new Asserter(
function(target) {
return target
.text().then(function(text) {
text.should.have.length.above(0);
return text;
})
.catch(tagChaiAssertionError);
}
);

driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");

driver
.init(desiredCaps)
.then(function () {
return driver.waitForElementById('TestBrowserStackLocal', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (testElement) {
return testElement.click();
})
.then(function () {
return driver.waitForElementById('ResultBrowserStackLocal', asserters.isDisplayed, 30000);
})
.then(function (resultElement) {
return resultElement.text().should.eventually.include('Up and running');
})
.fin(function() { return driver.quit(); })
.done();
57 changes: 57 additions & 0 deletions ios/singleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var wd = require('wd');
var assert = require('assert');
var asserters = wd.asserters;
var sleep = require('sleep');
var Q = wd.Q;

desiredCaps = {
'browserstack.user' : 'BROWSERSTACK_USERNAME',
'browserstack.key' : 'BROWSERSTACK_ACCESS_KEY',
'build' : 'Node iOS',
'name': 'single_test',
'device' : 'iPhone 7 Plus',
'app' : 'bs://<hashed app-id>',
'browserstack.debug' : true,
'realMobile' : true
};
driver = wd.promiseRemote("http://hub.browserstack.com/wd/hub");

driver
.init(desiredCaps)
.then(function () {
return driver.waitForElementById('Log In', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (loginButton) {
return loginButton.click();
})
.then(function () {
return driver.waitForElementById('Email address', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (emailInput) {
return emailInput.sendKeys("hello@browserstack.com");
})
.then(function () {
return driver.waitForElementById('Next', asserters.isDisplayed, 30000);
})
.then(function (nextButton) {
return nextButton.click().then(function() {
sleep.sleep(5);
});
})
.then(function() {
return driver.waitForElementsByXPath("//XCUIElementTypeStaticText", asserters.isDisplayed, 30000);
})
.then(function (textElements) {
return Q().then(function () {
return textElements.map(function (textElement) {
return textElement.text().then(function(value) {
if (value.indexOf('not registered') !== -1) {
console.log(value);
assert(value.indexOf('This email address is not registered on WordPress.com') !== -1);
}
});
})
}).all()
})
.fin(function() { return driver.quit(); })
.done();