Skip to main content

Integrate your tests with BrowserStack

The WebdriverIO service enables you to integrate your test suite with BrowserStack in simple steps. In this guide, you will learn to:

  1. Integrate your tests
  2. Debug your app

Integrate your tests

To integrate your WebdriverIO tests with BrowserStack, follow the steps below:

Step 1: Add the @browserstack/wdio-browserstack-service as a dependency in your package.json:

package.json
"devDependencies": {
  "@browserstack/wdio-browserstack-service": "^1",
}

Step 2: Install the dependencies using the npm command:

npm install

Step 3: Set your BrowserStack credentials in the webdriverio.conf.js file as shown below:

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

Alternatively, you can set the environment variables in your system as shown below:

# Set these values in your ~/.zprofile (zsh) or ~/.profile (bash)
  export BROWSERSTACK_USERNAME="YOUR_USERNAME"
  export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"
# setx.exe does not set the environment variable in the current command prompt, but it will be available in subsequent command prompts
  setx BROWSERSTACK_USERNAME="YOUR_USERNAME"
  setx BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"

# Verify whether the variables have been set
echo BROWSERSTACK_USERNAME
echo BROWSERSTACK_ACCESS_KEY

Step 4: Add the @browserstack/wdio-browserstack-service in the webdriverio.conf.js file as shown below:

webdriverio.conf.js
  exports.config = {
    ...
    services: [
      ['@browserstack/wdio-browserstack-service']
    ]
  };

Step 5: Trigger your existing build command to run your WebdriverIO test on BrowserStack.

Note: We have used @wdio/sync to run WebdriverIO commands synchronously. Use await to avoid commands running in async mode.

Debug your app

BrowserStack provides a range of debugging tools to help you quickly identify and fix bugs you discover through your automated tests. Learn more about how to debug tests on BrowserStack using the Automate Dashboard.

Text logs

Text Logs are a comprehensive record of your test. They are used to identify all the steps executed in the test and troubleshoot errors for the failed step. Text Logs are accessible from the Automate dashboard or via our REST API.

Visual logs

Visual Logs automatically capture the screenshots generated at every Selenium command run through your WebdriverIO tests. Visual logs help with debugging the exact step and the page where failure occurred. They also help identify any layout or design related issues with your web pages on different browsers.

Visual Logs are disabled by default. In order to enable Visual Logs you will need to set browserstack.debug capability to ‘true’.

//webdriverio.conf.js

capabilities: [{
  'browserstack.debug': true
}]

Video recording

Every test run on the BrowserStack Selenium grid is recorded exactly as it is executed on our remote machine. This feature is particularly helpful whenever a browser test fails. You can access videos from Automate Dashboard for each session. You can also download the videos from the Dashboard or retrieve a link to download the video using our REST API.

Note: Video recording increases test execution time slightly. You can disable this feature by setting the browserstack.video capability to false.

Console logs

Console Logs capture the browser’s console output at various steps of the test to troubleshoot javascript issues. You can retrieve Console Logs using an URL that you can get from our REST API. You will also be able to download logs from Automate Dashboard.

Console Logs are enabled with log level set to ‘errors’ by default. To set different log levels, you need to use the capability browserstack.console with values disable, errors, warnings, info or verbose, as shown below:

//webdriverio.conf.js

capabilities: [{
  'browserstack.console': <log-level>
}]

Network logs

Network Logs capture the browser’s performance data such as network traffic, latency, HTTP requests and responses in the HAR format. You can download network logs using a link that you can get from our REST API or from the Automate Dashboard.

Network Logs are disabled by default. To enable Network Logs use the capability browserstack.networkLogs with the value true, as shown below:

//webdriverio.conf.js

capabilities: [{
  'browserstack.networkLogs': true
}]
Note: If you want to refer a sample build, check the wdio repo webdriverio-browserstack sample repo on GitHub

Next steps

Once you have successfully integrated your test suite with BrowserStack, you might want to check the following:

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