---
title: Run Selenium tests with NodeJS and WebDriverIO.
description: Cross browser testing with NodeJS and Selenium
source_url:
  html: https://testingbot.com/support/web-automate/selenium/nodejs/webdriverio
  md: https://testingbot.com/support/web-automate/selenium/nodejs/webdriverio/index.md
---
### WebDriverIO Examples:

- [Cucumber](https://testingbot.com#cucumber)
- [Mocha](https://testingbot.com#mocha)
- [Jasmine](https://testingbot.com#jasmine)

# NodeJS Automated Testing with WebdriverIO

With WebDriverIO you can run [Mocha](https://testingbot.com#mocha), [Jasmine](https://testingbot.com#jasmine) (v2.0) and [Cucumber](https://testingbot.com#cucumber) tests.

See our [WebdriverIO examples repository](https://github.com/testingbot/webdriverio-examples) for some examples on how to use WebdriverIO with TestingBot. TestingBot has its own [WebDriverIO service](https://webdriver.io/docs/testingbot-service.html) plugin which makes configuring your tests easier and which sends test meta-data back to TestingBot.

Let's start with making sure `webdriverio` is installed:

    npm i --save-dev @wdio/cli @wdio/local-runner

## WebDriverIO TestingBot Service

WebDriverIO contains a [TestingBot service](https://webdriver.io/docs/testingbot-service.html) which makes it easy to run tests with WebDriver.io on TestingBot. With this service, WebDriverIO will start a [TestingBot Tunnel](https://testingbot.com/support/tunnel) if required, and send back test meta-data (passed state, name, build-id, ...)

In order to use the service you need to install it:

    npm install @wdio/testingbot-service --save-dev

## Cucumber Example

To run Cucumber tests on TestingBot, please follow these steps:

    npm install @wdio/testingbot-service --save-dev
    npm install @wdio/dot-reporter --save-dev
    npm install @wdio/cucumber-framework --save-dev

Now we'll make a simple Cucumber test which uses Firefox on TestingBot to go to Google.com and verify the page's title.

Please create the following files:

**wdio.conf.js**

    exports.config = {
    
      /**
       * specify test files
       */
      specs: [
        './features/*.feature'
      ],
    
      /**
       * capabilities
       */
      capabilities: [{
        browserName: 'chrome',
        browserVersion: 'latest',
        platformName: 'WIN11'
      }],
    
      /**
       * test configurations
       */
      logLevel: 'silent',
      waitforTimeout: 10000,
      connectionRetryTimeout: 480000,
      framework: 'cucumber',
      services: [
        ['testingbot']
      ],
      user: 'API_KEY',
      key: 'API_SECRET',
    
      reporters: ['dot'],
    
      cucumberOpts: {
        require: ['./step-definitions.js']
      }
    };

**step-definitions.js**

    const { Given, When, Then } = require('@cucumber/cucumber')
    const assert = require('assert')
    
    Given('I go on the website {string}', async (url) => {
      await browser.url(url)
    })
    
    Then('should the title of the page be {string}', async (expectedTitle) => {
      assert.equal(await browser.getTitle(), expectedTitle)
    })

**features/my-feature.feature**

    Feature: Example feature
    As a user of Google
    I should be able to go to Google and see its correct title
    
    Scenario: Get title of website
    Given I go on the website "https://www.google.com/"
    Then should the title of the page be "Google"

Now we can run this test on TestingBot!   
 To start the test, please run this command:

    npx wdio run wdio.conf.js

The test will now run on TestingBot. At the end of the test, the testname and success state will be available on TestingBot, together with a video and other meta-data.

## Mocha Example

To run Mocha tests on TestingBot, please follow these steps:

    npm install @wdio/testingbot-service --save-dev
    npm install @wdio/dot-reporter --save-dev
    npm install @wdio/mocha-framework --save-dev

Now we'll make a simple Mocha test which uses Firefox on TestingBot to go to Google.com and verify the page's title.

Please create the following files:

**wdio.conf.js**

    exports.config = {
    
      /**
       * specify test files
       */
      specs: [
        './runner-specs/mocha.test.js'
      ],
    
      /**
       * capabilities
       */
      capabilities: [{
        browserName: 'chrome',
        browserVersion: 'latest',
        platformName: 'WIN11'
      }],
    
      /**
       * test configurations
       */
      logLevel: 'silent',
      waitforTimeout: 10000,
      connectionRetryTimeout: 480000,
      framework: 'mocha',
      services: [
        ['testingbot']
      ],
      user: 'API_KEY',
      key: 'API_SECRET',
    
      reporters: ['dot'],
    
      mochaOpts: {
        ui: 'bdd'
      }
    };

**runner-specs/mocha.test.js**

    const assert = require('assert');
    describe('google page', async function() {
      it('should have the right title', async function () {
        await browser.url('https://www.google.com');
        const title = await browser.getTitle();
        assert.equal(title, 'Google');
      });
    });

Now we can run this test on TestingBot.   
 To start the test, please run this command:

    npx wdio run wdio.conf.js

The test will now run on TestingBot. At the end of the test, the testname and success state will be available on TestingBot, together with a video and other meta-data.

## Jasmine Example

To run Jasmine tests on TestingBot, please follow these steps:

    npm install @wdio/testingbot-service --save-dev
    npm install @wdio/dot-reporter --save-dev
    npm install @wdio/jasmine-framework --save-dev

Now we'll make a simple Jasmine test which uses Firefox on TestingBot to go to Google.com and verify the page's title.

Please create the following files:

**wdio.conf.js**

    exports.config = {
    
      /**
       * specify test files
       */
      specs: [
        './runner-specs/jasmine.spec.js'
      ],
    
      /**
       * capabilities
       */
      capabilities: [{
        browserName: 'chrome',
        browserVersion: 'latest',
        platformName: 'WIN11'
      }],
    
      /**
       * test configurations
       */
      logLevel: 'silent',
      waitforTimeout: 10000,
      connectionRetryTimeout: 480000,
      framework: 'jasmine',
      services: [
        ['testingbot']
      ],
      user: 'API_KEY',
      key: 'API_SECRET',
    
      reporters: ['dot'],
    
      jasmineOpts: {
        defaultTimeoutInterval: 9999999
      }
    };

**runner-specs/jasmine.spec.js**

    describe('google page', function() {
      it('should have the right title', async function () {
        await browser.url('https://www.google.com');
        const title = await browser.getTitle();
        expect(title).toBe('Google');
      });
    });

Now we can run this test on TestingBot.   
 To start the test, please run this command:

    npx wdio run wdio.conf.js

The test will now run on TestingBot. At the end of the test, the testname and success state will be available on TestingBot, together with a video and other meta-data.

## Specify Browsers & Devices

To let TestingBot know on which browser/platform/device you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.

  ![OS selected](https://testingbot.com/assets/environments/svg/windows11-0e1b28bc0fdd5034d3e4d3dc8d346c500a8c6522facf4b45d0da56537c1f1c6d.svg) Windows 11 › ![Browser Selected](https://testingbot.com/assets/environments/svg/chrome-c4081ff447d2d898d4afcb8f074a907c960e6f007716c1a1d119eee6803c4042.svg) Chrome 139 

Loading environments...

Please wait while we load the available browsers and platforms.

    

When running mobile tests with WebdriverIO, especially on real devices, make sure to specify a large enough `connectionRetryTimeout` in case a device is in use:

    connectionRetryTimeout: 480000

## Testing Internal Websites

We've built [TestingBot Tunnel](https://testingbot.com/support/tunnel), to provide you with a secure way to run tests against your staged/internal webapps.  
Please see our [TestingBot Tunnel documentation](https://testingbot.com/support/tunnel) for more information about this easy to use tunneling solution.

The example below shows how to easily run a WebDriverIO test with our Tunnel:

1. Adjust your `wdio.conf.js` configuration to use `tbTunnel: true`.   
 The [wdio-testingbot-service](https://webdriver.io/docs/testingbot-service/) will automatically download and use the tunnel for your tests.

**wdio.conf.js**

    exports.config = {
      services: [
        ['testingbot', {
          tbTunnel: true
        }]
      ],
      user: 'API_KEY',
      key: 'API_SECRET'
    };

## Run Tests in Parallel

Parallel testing allows you to run multiple tests at the same time, significantly reducing your total test execution time.

You can run the same test across different browser configurations, or run different tests on the same configuration, all simultaneously.   
 TestingBot provides a large grid of browsers and devices, enabling you to run tests in parallel efficiently. This is one of our core features designed to help you test faster and ship more reliably.

With WebDriverIO, you can enable parallel test execution by setting the `maxInstances` property in your `wdio.conf.js` file and specifying multiple `capabilities`. This defines how many instances of the same browser can run in parallel. We recommend setting this value to match the number of parallel sessions allowed by your TestingBot plan.

    exports.config = {
      maxInstances: 5, // Adjust this based on your TestingBot plan
      capabilities: [{
        browserName: 'chrome',
        browserVersion: 'latest',
        platformName: 'WIN11'
      }, {
        browserName: 'firefox',
        browserVersion: 'latest',
        platformName: 'WIN11'
      }]
    };

### Queuing

Every TestingBot plan includes a fixed number of parallel test slots.   
 If you exceed this limit, additional tests will be automatically queued and executed as soon as slots become available, no tests will be dropped or skipped.

## Mark tests as passed/failed

As TestingBot has no way to determine whether your test passed or failed (it is determined by your business logic), we offer a way to send the test status back to TestingBot. This is useful if you want to see if a test succeeded or failed from the TestingBot member area.

If you are using the [wdio-testingbot-service](https://webdriver.io/docs/testingbot-service/) then your tests will automatically report back meta-data to TestingBot (like test success, name, stacktrace, ...)

## Common errors

Below are some common errors you might encounter when running WebDriverIO tests on TestingBot:

- `UND_ERR_HEADERS_TIMEOUT`

**Problem:** This error indicates that WebdriverIO did not receive a response in time. This might happen when requesting a device that is currently in use, or in case you are trying to run more tests in parallel than your plan allows and the tests have been [queued](https://testingbot.com#queuing) for a long time.

**Solution:** You can try adding the `connectionRetryTimeout` in your WebDriverIO configuration with a high enough value:

    connectionRetryTimeout: 480000

## Other NodeJS Framework examples

- [CodeceptJS](https://testingbot.com/support/web-automate/selenium/nodejs/codeceptjs)

Run acceptance tests with CodeceptJS on TestingBot.

- [Nightwatch](https://testingbot.com/support/web-automate/selenium/nodejs/nightwatch)

Nightwatch is an automated testing framework written in NodeJS.

- [TestCafe](https://testingbot.com/support/web-automate/selenium/nodejs/testcafe)

TestCafe is a NodeJS framework for end-to-end web testing.

- [Hermione](https://testingbot.com/support/web-automate/selenium/nodejs/hermione)

Hermione is a Test Framework similar to WebDriverIO, with automatic test retries and plugins.

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new)[Slack Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
