Skip to main content
No Result Found

Test Observability on WebdriverIO

Quick start guide to integrating BrowserStack Test Observability with WebdriverIO

Prerequisites

  • You have an account with BrowserStack (even a free trial works) and can get the Username and Access Key from your account profile.
  • You have a WebdriverIO test suite (its okay even if you do not run your tests on BrowserStack infrastructure).
  • You are using Node.js version 14 or above.

Integrate with Test Observability

You can use BrowserStack Test Observability both when you’re using BrowserStack’s devices and browsers to run your tests and also if you’re running tests locally on your laptop/CI system or even when you’re using some other cloud provider.

Please select your setup below to get started with an awesome debugging experience with Test Observability:

Follow these steps to start using BrowserStack Test Observability with your existing setup of WebdriverIO tests running on BrowserStack Automate or App Automate:

Update to the latest version of the browserstack-service npm package

Go to your WebdriverIO project’s root directory and run the following commands to update the installed version of @wdio/browserstack-service and later check the installed version:

You need to install @wdio/browserstack-service if you’re not already using it and configure it using the following steps:

Terminal
npm update @wdio/browserstack-service
npm list @wdio/browserstack-service

# Please ensure that you have @wdio/browserstack-service v7.36.0 or above (if using WDIO v7) or v8.33.1 or above (if using WDIO v8)


Please ensure that you now have @wdio/browserstack-service v7.36.0 or above (if using WDIO v7) or v8.33.1 or above (if using WDIO v8), before proceeding.

Set up the config file

Your wdio.conf.js file should include the Username and Access Key as in the following code snippet:

wdio.conf.js
  exports.config = {
    //...
    user: 'YOUR_USERNAME' || process.env.BROWSERSTACK_USERNAME,
    key: 'YOUR_ACCESS_KEY' || process.env.BROWSERSTACK_ACCESS_KEY,
    services: [
        ['browserstack', {
            testObservability: true,
            testObservabilityOptions: {
                'projectName': 'Specify your project name here. It should not be dynamic',
                'buildName': 'Specify your job name here. For e.g. `Nightly regression`. It should not be dynamic',
                'buildTag': 'Any build tag goes here. For e.g. ["Tag1","Tag2"]'
            },
        }]
    ],
    //...
  };

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate since Test Observability will automatically identify different build runs.

Restrict the characters in your projectName and buildName to alphanumeric characters (A-Z, a-z, 0-9), underscores (_), colons (:), and hyphens (-). Any other character will be replaced with a space.

Any other config parameters that are already existing can exist as it is.

Run your suite with BrowserStack Test Observability

Use your existing command that you use to trigger a run and data will automatically start getting sent to BrowserStack Test Observability.

Post build run completion, you will see the build URL of Test Observability. Alternatively, you can also navigate to your build run using Build Runs.

Visit Test Observability

Follow these steps to integrate your WebdriverIO tests with BrowserStack Test Observability:

Install the @wdio/browserstack-service npm package

You can use BrowserStack Test Observability even if your tests are running locally or on any other cloud service provider. All you’d need to do is add the @wdio/browserstack-service dependency to your project’s package.json as follows:

npm install @wdio/browserstack-service@^7.36.0 --save-dev
npm install @wdio/browserstack-service@^8.33.1 --save-dev

Set up your BrowserStack credentials in environment variables

Your BrowserStack account credentials need to be specified as environment variables. You can find your account credentials in Account Profile. Even a free trial account on BrowserStack is good enough to use Test Observability for now.

# 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

Set up the webdriverIO config for Test Observability

Your wdio.conf.js should include the Username and the Access Key as in the following code snippet:

wdio.conf.js
  exports.config = {
    //...
    services: [
        ['browserstack', {
            testObservability: true,
            testObservabilityOptions: {
                user: 'YOUR_USERNAME' || process.env.BROWSERSTACK_USERNAME,
                key: 'YOUR_ACCESS_KEY' || process.env.BROWSERSTACK_ACCESS_KEY,
                projectName: 'Specify your project name here. It should not be dynamic',
                buildName: 'Specify your job name here. For e.g. `Nightly regression`. It should not be dynamic',
                buildTag: 'Any build tag goes here. For e.g. ["Tag1","Tag2"]'
            },
        }]
    ],
    //...
  };

Any other config parameters that are already existing can exist as it is. Please note that the user and key variables need to be specified inside the browserstack service config. If you specify the user and key outside, then BrowserStack Automate / App Automate infrastructure will be used to run the tests.

Run your suite with BrowserStack Test Observability

Use your existing command that you use to trigger a run and data will automatically start getting sent to BrowserStack Test Observability.

Post build run completion, you will see the build URL of Test Observability. Alternatively, you can also navigate to your build run using Build Runs.

Visit Test Observability

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
Download Copy Check Circle