Skip to main content
Start running your tests on the latest iOS minor versions on BrowserStack App Automate. Check out our documentation!

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 written using WebDriverIO on real Android and iOS devices on BrowserStack. In this guide, you will learn how to :

  1. Setup your environment
  2. Upload your app
  3. Configure and run your first test
  4. View test execution results

1. Setup your environment

  • You will need a BrowserStack username and access_key. If you haven’t created an account yet, sign up for a free trial or purchase a paid plan. After signup, you can obtain your access credentials from account settings
  • Ensure you have Node.js 8.11.2+ installed on your system. You can download updated Node version from nodejs.org
  • You will need access to your Android app (.apk or .aab file) or iOS app (.ipa file)
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 or sample iOS app.

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 app on App Automate :

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

Ensure that @ symbol is prepended to the file path in the above request. A sample response for the above request is shown below:

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

Please note the app_url value returned in the API response (bs://j3c874..... in the above example). We will use this value to set the application under test while configuring the test later on.

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 your first test

Setup your project

Clone the WebdriverIO sample integration code from our GitHub repository.

git clone https://github.com/browserstack/webdriverio-appium-app-browserstack.git

Next, execute the following commands in project’s base directory to install the required dependencies:

# Test an android app
cd android
npm i

# Test an iOS app
cd ios
npm i

This will install requisite dependencies including WebdriverIO package :

//...
  "dependencies": {
    "@wdio/cli": "^5.20.1",
    "@wdio/local-runner": "^5.20.1",
    "@wdio/mocha-framework": "^5.18.7",
    "browserstack-local": "^1.4.5"
  }
//...

Configure Appium’s desired capabilities

Desired capabilities are a series of key-value pairs that allow you to configure your Appium tests on BrowserStack. The following capabilities are required :

  • app capability : Its used to specify your uploaded app that will be installed on device during test execution. Use the app_url obtained in Upload your App section to set its value.
  • device capability : Its used to specify the BrowserStack device you want to run the test on.

In the WebdriverIO sample integration code, Appium’s desired capabilities are defined in the first.conf.js file located in the examples/run-first-test directory :


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

  //...

  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://<app-id>',
    'browserstack.debug': true
  }],

  // ...
};


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

  //...

  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://<app-id>',
    'browserstack.debug': true
  }],

  //...  
};

Note:

Create remote Webdriver

Once you have configured desired capabilities, you can initialize an Appium webdriver to test remotely on BrowserStack. In order to do so, provide your BrowserStack access credentials in user and key parameters and our WebdriverIO integration will automatically initialize the remote webdriver with your access credentials set in the config file.

In the WebdriverIO sample integration code, you can define BrowserStack user and key credentials in the first.conf.js file located in the examples/run-first-test directory :

//...

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

//...

Setup your test-case

This step will help you setup your first test case with WebdriverIO framework. In the WebdriverIO sample integration code, we have provided a sample test-case in examples/run-first-test/specs directory for BrowserStack’s sample apps. If you are testing your own app, please modify the test case accordingly.

If you are using your own app, modify the following code as per your test case :

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);
  });
});

If you are using your own app, modify the following code as per your test case :

var assert = require('assert');

describe('Text Verification', () => {
  it('should match displayed text with input text', async () => {
    var textButton = await $(`~Text Button`);
    await textButton.waitForDisplayed({ timeout: 30000 });
    await textButton.click();

    var textInput = await $(`~Text Input`);
    await textInput.waitForDisplayed({ timeout: 30000 });
    await textInput.click()
    await textInput.addValue("hello@browserstack.com"+"\n");

    var textOutput = await $(`~Text Output`);
    await textOutput.waitForDisplayed({ timeout: 30000 });
    var value = await textOutput.getText();

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

Run the test

You are ready to run your first WebdriverIO test on BrowserStack. In the WebdriverIO sample integration code, switch to android/ or ios/ directory, and run the test using command :

# Run using npm
npm run first

4. View test execution results

You can access the test execution results, and debugging information such as video recording, network and device logs on App Automate dashboard or using our REST APIs.

What’s next

Congratulations! You just ran your first test on App Automate. Next, you can learn to :

  • Run tests in parallel - Speed up test execution by running tests simultaneously across multiple BrowserStack devices
  • Use Local testing - Test apps that access resources hosted on your development or testing environments

Need some help?

If you have any queries, please get in touch with us.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert