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
60 changes: 54 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
# webdriverio-appium-app-browserstack
[WebdriverIO](http://webdriver.io/) Integration with BrowserStack.
This repository demonstrates how to run Appium tests using [WebdriverIO](http://webdriver.io/) on BrowserStack App Automate.

![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)

<img src = "http://webdriver.io/images/webdriverio.png" height = "100">
<div align="center">
<img src = "https://www.browserstack.com/images/layout/browserstack-logo-600x315.png" > <br>
<img src = "https://webdriver.io/img/webdriverio.png" height="140px">
</div>

Code samples to get started with Appium tests for your Native App using WebdriverIO.

## Resources
* [Get Started guide](https://www.browserstack.com/app-automate/appium-webdriverio)
## Setup

### Requirements

* Node.js 8.11.2+
- If you don't have Node installed, download it from [here](https://nodejs.org/en/)

### Install the dependencies

For Android tests, run the following command in project's base directory :

```sh
cd android
npm i
```

Or,

For dependencies for iOS tests, run following command in project's base directory :

```sh
cd ios
npm i
```

## Getting Started

Getting Started with Appium tests using WebdriverIO on BrowserStack couldn't be easier!

### Run first test:
- Test script is available in `run-first-test` directory under [Android examples](./android) or [iOS examples](./ios)
- Follow the steps outlined in the documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/nodejs/webdriverio)

### Speed up test execution with parallel testing :

- Test script is available in `run-parallel-test` directory under [Android examples](./android) or [iOS examples](./ios)
- Follow the steps outlined in the documentation - [Get Started with parallel testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/nodejs/webdriverio/parallelize-tests)

### Use Local testing for apps that access resources hosted in development or testing environments :

- Test script is available in `run-local-test` directory under [Android examples](./android) or [iOS examples](./ios)
- Follow the steps outlined in the documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/nodejs/webdriverio/local-testing)

**Note**: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)

## Getting Help

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).

32 changes: 0 additions & 32 deletions android/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
exports.config = {
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACC_KEY',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',

updateJob: false,
specs: [
'./tests/specs/single_test.js'
'./examples/run-first-test/specs/first_test.js'
],
exclude: [],

capabilities: [{
name: 'single_appium_test',
build: 'webdriver-browserstack',
device: 'Samsung Galaxy S7',
browserName: 'android',
project: "First Webdriverio Android Project",
build: 'Webdriverio Android',
name: 'first_test',
device: 'Google Pixel 3',
os_version: "9.0",
app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
'browserstack.debug': true
}],

logLevel: 'verbose',
logLevel: 'info',
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
Expand Down
18 changes: 18 additions & 0 deletions android/examples/run-first-test/specs/first_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var assert = require('assert');

describe('Search Wikipedia Functionality', () => {
it('can find search results', async () => {
var searchSelector = await $(`~Search Wikipedia`);
await searchSelector.waitForDisplayed({ timeout: 30000 });
await searchSelector.click();

var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
await insertTextSelector.waitForDisplayed({ timeout: 30000 });

await insertTextSelector.addValue("Browsertack");
await browser.pause(5000);

var allProductsName = await $$(`android.widget.TextView`);
assert(allProductsName.length > 0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ var browserstack = require('browserstack-local');

exports.config = {
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACC_KEY',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',

updateJob: false,
specs: [
'./tests/specs/local_test.js'
'./examples/run-local-test/specs/local_test.js'
],
exclude: [],

capabilities: [{
name: 'local_appium_test',
build: 'webdriver-browserstack',
device: 'Google Pixel',
browserName: 'android',
project: "First Webdriverio Android Project",
build: 'Webdriverio Android Local',
name: 'local_test',
device: 'Google Pixel 3',
os_version: "9.0",
app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
'browserstack.local': true,
'browserstack.debug': true
}],

logLevel: 'verbose',
logLevel: 'info',
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
Expand All @@ -35,11 +36,11 @@ exports.config = {
},

// Code to start browserstack local before start of test
onPrepare: function (config, capabilities) {
onPrepare: (config, capabilities) => {
console.log("Connecting local");
return new Promise(function(resolve, reject){
return new Promise( (resolve, reject) => {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': exports.config.key }, function(error) {
exports.bs_local.start({'key': exports.config.key }, (error) => {
if (error) return reject(error);
console.log('Connected. Now testing...');

Expand All @@ -49,7 +50,15 @@ exports.config = {
},

// Code to stop browserstack local after end of test
onComplete: function (capabilties, specs) {
exports.bs_local.stop(function() {});
onComplete: (capabilties, specs) => {
console.log("Closing local tunnel");
return new Promise( (resolve, reject) => {
exports.bs_local.stop( (error) => {
if (error) return reject(error);
console.log("Stopped BrowserStackLocal");

resolve();
});
});
}
};
32 changes: 32 additions & 0 deletions android/examples/run-local-test/specs/local_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var path = require('path');
var assert = require('assert');

describe('BrowserStack Local Testing', () => {
it('can check tunnel working', async () => {
var searchSelector = await $('android=new UiSelector().resourceId("com.example.android.basicnetworking:id/test_action")');
await searchSelector.waitForDisplayed({ timeout: 30000 });
await searchSelector.click();

var insertTextSelector = await $(`android.widget.TextView`);
await insertTextSelector.waitForDisplayed({ timeout: 30000 });

var testElement = null;

try {
var textElement = await $('android=new UiSelector().textContains("active connection is")');
await textElement.waitForDisplayed({ timeout: 30000 });
testElement = textElement;
}
catch {
var screenshotPath = path.resolve(__dirname, 'screenshot.png');
await browser.saveScreenshot(screenshotPath);
console.log('Screenshot stored at ' + screenshotPath);
throw new Error('Cannot find the needed TextView element from app');
}

var matchedString = await testElement.getText();
console.log(matchedString);
assert(matchedString.indexOf('The active connection is wifi') !== -1);
assert(matchedString.indexOf('Up and running') !== -1);
});
});
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
exports.config = {
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACC_KEY',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',

updateJob: false,
specs: [
'./tests/specs/multiple_test.js'
'./examples/run-multiple-test/specs/multiple_test.js'
],
exclude: [],

capabilities: [{
name: 'multiple_appium_test',
build: 'webdriver-browserstack',
device: 'Google Nexus 9',
browserName: 'android',
project: "First Webdriverio Android Project",
build: 'Webdriverio Android Multiple',
name: 'multiple_test',
device: 'Google Pixel 3',
os_version: "9.0",
app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
'browserstack.debug': true
}],

logLevel: 'verbose',
logLevel: 'info',
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
Expand Down
18 changes: 18 additions & 0 deletions android/examples/run-multiple-test/specs/multiple/test_01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var assert = require('assert');

describe('Search Wikipedia Functionality', () => {
it('can find search results', async () => {
var searchSelector = await $(`~Search Wikipedia`);
await searchSelector.waitForDisplayed({ timeout: 30000 });
await searchSelector.click();

var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
await insertTextSelector.waitForDisplayed({ timeout: 30000 });

await insertTextSelector.addValue("Browsertack01");
await browser.pause(5000);

var allProductsName = await $$(`android.widget.TextView`);
assert(allProductsName.length > 0);
});
});
18 changes: 18 additions & 0 deletions android/examples/run-multiple-test/specs/multiple/test_02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var assert = require('assert');

describe('Search Wikipedia Functionality', () => {
it('can find search results', async () => {
var searchSelector = await $(`~Search Wikipedia`);
await searchSelector.waitForDisplayed({ timeout: 30000 });
await searchSelector.click();

var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
await insertTextSelector.waitForDisplayed({ timeout: 30000 });

await insertTextSelector.addValue("Browsertack02");
await browser.pause(5000);

var allProductsName = await $$(`android.widget.TextView`);
assert(allProductsName.length > 0);
});
});
18 changes: 18 additions & 0 deletions android/examples/run-multiple-test/specs/multiple/test_03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var assert = require('assert');

describe('Search Wikipedia Functionality', () => {
it('can find search results', async () => {
var searchSelector = await $(`~Search Wikipedia`);
await searchSelector.waitForDisplayed({ timeout: 30000 });
await searchSelector.click();

var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
await insertTextSelector.waitForDisplayed({ timeout: 30000 });

await insertTextSelector.addValue("Browsertack03");
await browser.pause(5000);

var allProductsName = await $$(`android.widget.TextView`);
assert(allProductsName.length > 0);
});
});
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
exports.config = {
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACC_KEY',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',

updateJob: false,
specs: [
'./tests/specs/single_test.js'
'./examples/run-parallel-test/specs/single_test.js'
],
exclude: [],

maxInstances: 10,
commonCapabilities: {
name: 'parallel_appium_test',
build: 'webdriver-browserstack',
browserName: 'android',
project: "First Webdriverio Android Project",
build: 'Webdriverio Android Parallel',
name: 'parallel_test',
app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
'browserstack.debug': true
},

capabilities: [{
device: 'Google Pixel'
device: 'Google Pixel 3',
os_version: "9.0"
}, {
device: 'Samsung Galaxy S7'
}, {
device: 'Samsung Galaxy S6'
}, {
device: 'Google Nexus 9'
device: 'Samsung Galaxy S10e',
os_version: "9.0"
}],

logLevel: 'verbose',
logLevel: 'info',
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
Expand Down
Loading