Features

Jest Testing

See the TestingBot Jest example repository for an example on how to run Jest tests with remote TestingBot browsers.

Jest is a popular open-source testing framework for JavaScript applications, developed and maintained by Facebook. It is widely used for testing React applications but is versatile enough to test any JavaScript codebase. Jest provides a simple, intuitive API for writing unit tests, integration tests and end-to-end tests.

Setting up Jest

To run Jest tests with WebDriver, you first have to make sure both the Jest NPM package and the Selenium WebDriver NPM package are added to your project.

Copy code
npm install --save-dev jest selenium-webdriver

You can now add a jest.config.js configuration file, which consists of a few options that Jest will use.

Copy code
module.exports = {
  testEnvironment: 'node',
  testTimeout: 60000, // Extend timeout for Selenium tests
  coverageProvider: "v8",
  maxConcurrency: 5,
  maxWorkers: 5,
  testPathIgnorePatterns: ["/node_modules/"]
};

Jest Tests

Now we can create our first Jest test. We'll create a new file in a directory called __tests__, called single.test.js

Copy code
const webdriver = require("selenium-webdriver")

describe("TestingBot example test", () => {
  let driver

  beforeAll(() => {
    const tbKey = process.env.TESTINGBOT_KEY
    const tbSecret = process.env.TESTINGBOT_SECRET
    const capabilities = {
     'platformName' : 'WIN10',
     'browserName' : 'chrome',
     'browserVersion' : 'latest',
     'tb:options': {
       'name': 'Jest Sample Test'
      }
    }
    driver = new webdriver.Builder()
      .usingServer(`https://${tbKey}:${tbSecret}@hub.testingbot.com/wd/hub`)
      .withCapabilities(capabilities)
      .build()
  })

  afterAll(async () => {
    await driver.quit()
  })
  
  test("example test", async () => {
    await driver.get("https://testingbot.com")

    await driver.findElement(webdriver.By.css("body > div.bigHeader.home > nav > div > div.navigation-actions.is-desktop > a.button.button-trial")).click()

    expect(await driver.getCurrentUrl()).toBe(
      "https://testingbot.com/users/sign_up"
    )
  })
})

This example test will run on a remote Chrome browser on Windows 10 in the TestingBot cloud. The browser will navigate to the TestingBot website, click a button and verify the URL.

Run Jest test

Now that we have a test, we can run it on TestingBot. Before we can do this, make sure you get your key and secret from the TestingBot dashboard, to authenticate with the remote browser grid.

Now we can run the test:

Copy code
TESTINGBOT_KEY=... TESTINGBOT_SECRET=... jest

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.

Copy code

Testing Internal Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.

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

1. Download our tunnel and start the tunnel:

Copy code
java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to 'hub.testingbot.com/wd/hub' like the example above - change it to point to your tunnel's IP address.
Assuming you run the tunnel on the same machine you run your tests, change to 'localhost:4445/wd/hub'. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.

This way your test will go securely through the tunnel to TestingBot and back:

Copy code
driver = new webdriver.Builder()
      .usingServer(`http://localhost:4445/wd/hub`)
      .withCapabilities(capabilities)
      .build()

Run tests in Parallel

Parallel Testing means running the same test, or multiple tests, simultaneously. This greatly reduces your total testing time.

You can run the same tests on all different browser configurations or run different tests all on the same browser configuration.
TestingBot has a large grid of machines and browsers, which means you can use our service to do efficient parallel testing. It is one of the key features we provide to greatly cut down on your total testing time.

By default, Jest will run all tests simultaneously. You can use Jest's Sharding option to group tests together. For example, to split the suite into five shards, each running one fifth of the tests:

Copy code
jest --shard=1/5
jest --shard=2/5
jest --shard=3/5
jest --shard=4/5
jest --shard=5/5

Queuing

Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

Other NodeJS Framework examples

  • WebDriverIO

    With WebDriverIO you can run Mocha, Jasmine and Cucumber tests.

  • CodeceptJS

    Run acceptance tests with CodeceptJS on TestingBot.

  • Protractor

    Protractor is an end-to-end test framework for AngularJS applications. Protractor is a NodeJS program built on top of WebDriverJS.

  • Soda

    Selenium Node Adapter. A light-weight Selenium RC client for NodeJS.

  • Nightwatch

    Nightwatch is an automated testing framework written in NodeJS.

  • Intern

    Intern is a nodeJS framework for testing Web sites and applications.

  • WD.js

    WD.js is a NodeJS client for WebDriver/Selenium.