diff --git a/README.md b/README.md index ba30460..b01f363 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # webdriverio-appium-app-browserstack + This repository demonstrates how to run Appium tests using [WebdriverIO](http://webdriver.io/) on BrowserStack App Automate.
@@ -8,11 +9,18 @@ This repository demonstrates how to run Appium tests using [WebdriverIO](http:// Code samples to get started with Appium tests for your Native App using WebdriverIO. +## Based on + +These code samples are currently based on: + +- **WebdriverIO:** `7.23.0` +- **Protocol:** `W3C` + ## Setup ### Requirements -* Node.js 8.11.2+ +- Node.js v16.17.0+ - If you don't have Node installed, download it from [here](https://nodejs.org/en/) ### Install the dependencies @@ -38,12 +46,13 @@ npm i 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) + +- 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) +- 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 : @@ -56,4 +65,3 @@ Getting Started with Appium tests using WebdriverIO on BrowserStack couldn't be ## 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). - diff --git a/android/assets/SampleAndroidApp.apk b/android/assets/SampleAndroidApp.apk new file mode 100644 index 0000000..03d19e6 Binary files /dev/null and b/android/assets/SampleAndroidApp.apk differ diff --git a/android/assets/SampleLocalAndroidApp.apk b/android/assets/SampleLocalAndroidApp.apk new file mode 100644 index 0000000..e519680 Binary files /dev/null and b/android/assets/SampleLocalAndroidApp.apk differ diff --git a/android/examples/run-first-test/first.conf.js b/android/examples/run-first-test/first.conf.js index aa83cf6..bd736da 100644 --- a/android/examples/run-first-test/first.conf.js +++ b/android/examples/run-first-test/first.conf.js @@ -9,13 +9,14 @@ exports.config = { exclude: [], capabilities: [{ - 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://', - 'browserstack.debug': true + platformName: "Android", + "appium:platformVersion": "9.0", + "appium:deviceName": 'Google Pixel 3', + 'bstack:options' : { + "projectName" : "First Webdriverio Android Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -25,6 +26,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleAndroidApp.apk' + }]], framework: 'mocha', mochaOpts: { diff --git a/android/examples/run-local-test/local.conf.js b/android/examples/run-local-test/local.conf.js index 966c7c9..e033809 100644 --- a/android/examples/run-local-test/local.conf.js +++ b/android/examples/run-local-test/local.conf.js @@ -1,9 +1,15 @@ -var browserstack = require('browserstack-local'); - exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', + // Adding browserstackLocal to browserstack-service to initiate local binary + services: [ + ['browserstack', { + browserstackLocal: true, + app: 'assets/SampleLocalAndroidApp.apk' + }] + ], + updateJob: false, specs: [ './examples/run-local-test/specs/local_test.js' @@ -11,14 +17,14 @@ exports.config = { exclude: [], capabilities: [{ - 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://', - 'browserstack.local': true, - 'browserstack.debug': true + platformName: "Android", + "appium:platformVersion": "9.0", + "appium:deviceName": 'Google Pixel 3', + 'bstack:options' : { + "projectName" : "First Webdriverio Android Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -33,32 +39,5 @@ exports.config = { mochaOpts: { ui: 'bdd', timeout: 20000 - }, - - // Code to start browserstack local before start of test - onPrepare: (config, capabilities) => { - console.log("Connecting local"); - return new Promise( (resolve, reject) => { - exports.bs_local = new browserstack.Local(); - exports.bs_local.start({'key': exports.config.key }, (error) => { - if (error) return reject(error); - console.log('Connected. Now testing...'); - - resolve(); - }); - }); - }, - - // Code to stop browserstack local after end of test - 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(); - }); - }); } }; diff --git a/android/examples/run-multiple-test/multiple.conf.js b/android/examples/run-multiple-test/multiple.conf.js index c377060..d4c3170 100644 --- a/android/examples/run-multiple-test/multiple.conf.js +++ b/android/examples/run-multiple-test/multiple.conf.js @@ -9,13 +9,14 @@ exports.config = { exclude: [], capabilities: [{ - 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://', - 'browserstack.debug': true + platformName: "Android", + "appium:platformVersion": "9.0", + "appium:deviceName": 'Google Pixel 3', + 'bstack:options' : { + "projectName" : "First Webdriverio Android Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -25,6 +26,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleAndroidApp.apk' + }]], framework: 'mocha', mochaOpts: { diff --git a/android/examples/run-parallel-test/parallel.conf.js b/android/examples/run-parallel-test/parallel.conf.js index 930b16b..15413d9 100644 --- a/android/examples/run-parallel-test/parallel.conf.js +++ b/android/examples/run-parallel-test/parallel.conf.js @@ -10,19 +10,20 @@ exports.config = { maxInstances: 10, commonCapabilities: { - project: "First Webdriverio Android Project", - build: 'Webdriverio Android Parallel', - name: 'parallel_test', - app: process.env.BROWSERSTACK_APP_ID || 'bs://', - 'browserstack.debug': true + platformName: "Android", + 'bstack:options' : { + "projectName" : "First Webdriverio Android Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }, capabilities: [{ - device: 'Google Pixel 3', - os_version: "9.0" + "appium:deviceName": 'Google Pixel 3', + "appium:platformVersion": "9.0", }, { - device: 'Samsung Galaxy S10e', - os_version: "9.0" + "appium:deviceName": 'Samsung Galaxy S10e', + "appium:platformVersion": "9.0", }], logLevel: 'info', @@ -32,6 +33,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleAndroidApp.apk' + }]], framework: 'mocha', mochaOpts: { @@ -41,6 +45,6 @@ exports.config = { }; // Code to support common capabilities -exports.config.capabilities.forEach(function(caps){ - for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; -}); +var common_caps = exports.config.commonCapabilities +var caps = exports.config.capabilities +for (var i in caps) caps[i] = { ...caps[i], ...common_caps }; diff --git a/android/package.json b/android/package.json index 2cfca95..d17726d 100644 --- a/android/package.json +++ b/android/package.json @@ -1,8 +1,8 @@ { "name": "webdriverio-appium-app-browserstack", "version": "0.1.0", - "readme": "WendriverIO Integration with [BrowserStack](https://www.browserstack.com)", - "description": "Selenium examples for WebdriverIO and BrowserStack App Automate", + "readme": "WebdriverIO Integration with [BrowserStack](https://www.browserstack.com)", + "description": "Appium examples for WebdriverIO and BrowserStack App Automate", "scripts": { "test": "npm run first && npm run local && npm run parallel", "first": "./node_modules/.bin/wdio examples/run-first-test/first.conf.js", @@ -25,9 +25,11 @@ }, "homepage": "https://github.com/browserstack/webdriverio-appium-app-browserstack#readme", "dependencies": { - "@wdio/cli": "^5.20.1", - "@wdio/local-runner": "^5.20.1", - "@wdio/mocha-framework": "^5.18.7", - "browserstack-local": "^1.4.5" + "@wdio/cli": "^7.23.0" + }, + "devDependencies": { + "@wdio/browserstack-service": "^7.25.0", + "@wdio/local-runner": "^7.25.0", + "@wdio/mocha-framework": "^7.25.0" } } diff --git a/ios/assets/SampleIosApp.ipa b/ios/assets/SampleIosApp.ipa new file mode 100644 index 0000000..c1891b8 Binary files /dev/null and b/ios/assets/SampleIosApp.ipa differ diff --git a/ios/assets/SampleLocalIosApp.ipa b/ios/assets/SampleLocalIosApp.ipa new file mode 100644 index 0000000..97d41a4 Binary files /dev/null and b/ios/assets/SampleLocalIosApp.ipa differ diff --git a/ios/examples/run-first-test/first.conf.js b/ios/examples/run-first-test/first.conf.js index 2462928..90f6a18 100644 --- a/ios/examples/run-first-test/first.conf.js +++ b/ios/examples/run-first-test/first.conf.js @@ -9,13 +9,14 @@ exports.config = { exclude: [], capabilities: [{ - project: "First Webdriverio iOS Project", - build: 'Webdriverio iOS', - name: 'single_test', - device: 'iPhone 11 Pro', - os_version: "13", - app: process.env.BROWSERSTACK_APP_ID || 'bs://', - 'browserstack.debug': true + platformName: "ios", + "appium:platformVersion": "13", + "appium:deviceName": 'iPhone 11 Pro', + 'bstack:options' : { + "projectName" : "First Webdriverio iOS Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -25,6 +26,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleIosApp.ipa' + }]], framework: 'mocha', mochaOpts: { diff --git a/ios/examples/run-local-test/local.conf.js b/ios/examples/run-local-test/local.conf.js index 8fd8bd3..66f5137 100644 --- a/ios/examples/run-local-test/local.conf.js +++ b/ios/examples/run-local-test/local.conf.js @@ -1,9 +1,15 @@ -var browserstack = require('browserstack-local'); - exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', + // Adding browserstackLocal to browserstack-service to initiate local binary + services: [ + ['browserstack', { + browserstackLocal: true, + app: 'assets/SampleLocalIosApp.ipa' + }] + ], + updateJob: false, specs: [ './examples/run-local-test/specs/local_test.js' @@ -11,14 +17,14 @@ exports.config = { exclude: [], capabilities: [{ - project: "First Webdriverio iOS Project", - build: 'Webdriverio iOS Local', - name: 'local_test', - device: 'iPhone 11 Pro', - os_version: "13", - app: process.env.BROWSERSTACK_APP_ID || 'bs://', - 'browserstack.local': true, - 'browserstack.debug': true + platformName: "ios", + "appium:platformVersion": "12", + "appium:deviceName": 'iPhone XS', + 'bstack:options' : { + "projectName" : "First Webdriverio iOS Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -34,31 +40,4 @@ exports.config = { ui: 'bdd', timeout: 30000 }, - - // Code to start browserstack local before start of test - onPrepare: (config, capabilities) => { - console.log("Connecting local"); - return new Promise( (resolve, reject) => { - exports.bs_local = new browserstack.Local(); - exports.bs_local.start({'key': exports.config.key }, (error) => { - if (error) return reject(error); - console.log('Connected. Now testing...'); - - resolve(); - }); - }); - }, - - // Code to stop browserstack local after end of test - 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(); - }); - }); - } }; diff --git a/ios/examples/run-local-test/specs/local_test.js b/ios/examples/run-local-test/specs/local_test.js index 94fdf1f..ef9e9d9 100644 --- a/ios/examples/run-local-test/specs/local_test.js +++ b/ios/examples/run-local-test/specs/local_test.js @@ -3,7 +3,7 @@ var assert = require('assert'); describe('BrowserStack Local Testing', () => { it('can check tunnel working', async () => { - var searchSelector = await $(`~Test BrowserStackLocal connection`); + var searchSelector = await $(`~TestBrowserStackLocal`); await searchSelector.waitForDisplayed({ timeout: 30000 }); await searchSelector.click(); @@ -25,6 +25,6 @@ describe('BrowserStack Local Testing', () => { } var matchedString = await testElement.getText(); - assert(matchedString == 'Response is: Up and running'); + assert(matchedString.includes('Up and running')); }); }); diff --git a/ios/examples/run-multiple-test/multiple.conf.js b/ios/examples/run-multiple-test/multiple.conf.js index b67b1eb..98949c9 100644 --- a/ios/examples/run-multiple-test/multiple.conf.js +++ b/ios/examples/run-multiple-test/multiple.conf.js @@ -9,13 +9,14 @@ exports.config = { exclude: [], capabilities: [{ - project: "First Webdriverio iOS Project", - build: 'Webdriverio iOS Multiple', - name: 'multiple_test', - device: 'iPhone 11 Pro', - os_version: "13", - app: process.env.BROWSERSTACK_APP_ID || 'bs://', - 'browserstack.debug': true + platformName: "ios", + "appium:platformVersion": "13", + "appium:deviceName": 'iPhone 11 Pro', + 'bstack:options' : { + "projectName" : "First Webdriverio iOS Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }], logLevel: 'info', @@ -25,6 +26,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleIosApp.ipa' + }]], framework: 'mocha', mochaOpts: { diff --git a/ios/examples/run-parallel-test/parallel.conf.js b/ios/examples/run-parallel-test/parallel.conf.js index 8012251..f4bc213 100644 --- a/ios/examples/run-parallel-test/parallel.conf.js +++ b/ios/examples/run-parallel-test/parallel.conf.js @@ -10,19 +10,20 @@ exports.config = { maxInstances: 10, commonCapabilities: { - project: "First Webdriverio iOS Project", - build: 'Webdriverio iOS Parallel', - name: 'parallel_test', - app: process.env.BROWSERSTACK_APP_ID || 'bs://', - 'browserstack.debug': true + platformName: "ios", + 'bstack:options' : { + "projectName" : "First Webdriverio iOS Project", + "buildName" : "browserstack-build-1", + "debug" : "true" + } }, capabilities: [{ - device: "iPhone 11 Pro", - os_version: "13" + "appium:deviceName": 'iPhone 11 Pro', + "appium:platformVersion": "13", }, { - device: "iPhone 11 Pro Max", - os_version: "13" + "appium:deviceName": 'iPhone 11 Pro Max', + "appium:platformVersion": "13", }], logLevel: 'info', @@ -32,6 +33,9 @@ exports.config = { waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, + services: [['browserstack', { + app: 'assets/SampleIosApp.ipa' + }]], framework: 'mocha', mochaOpts: { @@ -41,6 +45,6 @@ exports.config = { }; // Code to support common capabilities -exports.config.capabilities.forEach(function(caps){ - for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; -}); +var common_caps = exports.config.commonCapabilities +var caps = exports.config.capabilities +for (var i in caps) caps[i] = { ...caps[i], ...common_caps }; diff --git a/ios/package.json b/ios/package.json index 9b5953d..d17726d 100644 --- a/ios/package.json +++ b/ios/package.json @@ -1,8 +1,8 @@ { "name": "webdriverio-appium-app-browserstack", "version": "0.1.0", - "readme": "WendriverIO Integration with [BrowserStack](https://www.browserstack.com)", - "description": "Selenium examples for WebdriverIO and BrowserStack App Automate", + "readme": "WebdriverIO Integration with [BrowserStack](https://www.browserstack.com)", + "description": "Appium examples for WebdriverIO and BrowserStack App Automate", "scripts": { "test": "npm run first && npm run local && npm run parallel", "first": "./node_modules/.bin/wdio examples/run-first-test/first.conf.js", @@ -25,9 +25,11 @@ }, "homepage": "https://github.com/browserstack/webdriverio-appium-app-browserstack#readme", "dependencies": { - "browserstack-local": "^1.4.5", - "@wdio/cli": "^5.20.1", - "@wdio/local-runner": "^5.20.1", - "@wdio/mocha-framework": "^5.18.7" + "@wdio/cli": "^7.23.0" + }, + "devDependencies": { + "@wdio/browserstack-service": "^7.25.0", + "@wdio/local-runner": "^7.25.0", + "@wdio/mocha-framework": "^7.25.0" } }