Search by

Run your first test

BrowserStack App Automate enables you to test native and hybrid mobile applications using Appium automation framework. Its easy to run your Appium tests using WebDriverIO on real Android and iOS devices on BrowserStack. This guide will help you get started with your first test.

1. Setup

Ensure you have WebdriverIO libraries installed.

# Install using npm
npm install webdriverio

2. Upload your app

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 to upload the app :

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/app/file/Application-debug.apk"

A sample response for the above request is shown below:

{
    "app_url":"bs://j3c874f21852ba57957a3fdc33f47514288c4ba4"
}

Note the value of app_url returned in the API response (bs://j3c874f21852b..... in the above example). This value will be used later to set the app capability to specify application under test in your Appium test scripts.

Note:
  1. App upload will take a few seconds to about a minute depending on the size of your app. Do not interrupt the cURL command until you get the response back.
  2. If you upload an iOS app, we will re-sign the app with our own provisioning profile to be able to install your app on our devices during test execution.

3. Configure and run the test

In this step, you will learn how to configure your Appium test script using desired capabilities to test remotely on BrowserStack’s real device cloud. Here is a sample test case written for running with WebdriverIO:

If you are using our Sample App, the sample test below will install the Sample App (Wikipedia App) on the device, search for ‘browserstack’ and asserts for the list of results. If you are using your own app, modify the code as per your test cases.

var assert = require('assert');

describe('Search Wikipedia Functionality', function () {
  it('can find search results', function () {
    var searchSelector = `~Search Wikipedia`;
    browser.waitForVisible(searchSelector, 30000);
    browser
      .element(searchSelector)
      .click();

    var insertTextSelector = 'android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")';
    browser.waitForVisible(insertTextSelector);
    browser
      .element(insertTextSelector)
      .keys('BrowserStack')
      .pause(5000);

    var allProductsName = browser.elements(`android.widget.TextView`).value;
    assert(allProductsName.length > 0);
  });
});

If you are using our Sample App, the sample test below will install the Sample App (WordPress App) on the device, navigate to the Login screen, enters the login email and check whether the email is registered on WordPress. If you are using your own app, modify the code as per your test cases.

var assert = require('assert');

describe('Text Verification', function () {
  it('should match displayed text with input text', function () {
    var textButton = `~Text Button`;
    browser.waitForVisible(textButton, 30000);
    browser
      .element(textButton)
      .click();

    var textInput = `~Text Input`;
    browser.waitForVisible(textInput, 30000);
    browser
      .element(textInput)
      .click()
      .keys("hello@browserstack.com"+"\n");

    var textOutput = `~Text Output`;
    browser.waitForVisible(textOutput, 30000);
    var value = browser.getText(textOutput)

    if (value === "hello@browserstack.com")
      assert(true)
    else
      assert(false)

  });
});

To actually run the test case, we need to integrate with BrowserStack as follows:

Integration with BrowserStack

Note: Running your WebdriverIO tests on BrowserStack requires a username and an access key.

Integration of WebdriverIO with BrowserStack is made possible by the use of the following module:

exports.config = {
  user: 'YOUR_USERNAME',
  key: 'YOUR_ACCESS_KEY',

capabilities: [{
    name: 'single_appium_test',
    build: 'webdriver-browserstack',
    device: 'Google Pixel',
    app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
    'browserstack.debug': true
 }]
exports.config = {
  user: 'YOUR_USERNAME',
  key: 'YOUR_ACCESS_KEY',

 capabilities: [{
    name: 'single_appium_test',
    build: 'webdriver-browserstack',
    device: 'iPhone 7',
    app: process.env.BROWSERSTACK_APP_ID || 'bs://<hashed app-id>',
    'browserstack.debug': true
 }]

Note: Remember to update the app in the above module using the app_url(bs://…..) which was obtained after uploading the App to the BrowserStack cloud in Step 2.

Run your test on BrowserStack using following command:

# Run using npm
npm run single
Note: Refer to our GitHub repository for a complete example: BrowserStack - WebdriverIO

4. Viewing test results

You can access results of your test sessions on the App Automate dashboard as well as using our REST API. You can drill down into the details of a specific test session to view its execution details and debugging information such as video recording, network logs and device logs.