NodeJS Automated Testing with Webdriver.io

With webdriver.io you can run Mocha, Jasmine (v2.0) and Cucumber tests.


TestingBot has its own webdriver.io service 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 install -g webdriverio


You are now ready to run a WebDriver test with NodeJS on our grid.
Please take a look at the following example, this demonstrates webdriver.io without any test frameworks:


var webdriverio = require('webdriverio'),
client = webdriverio.remote({
	desiredCapabilities: {
		browserName: 'firefox', version: '45', platform: 'WINDOWS', name: 'This is an example test'
	},
	host: 'hub.testingbot.com',
	port: 80,
	user: 'api_key',
	key: 'api_secret'
}).init();

client
	.url('https://google.com')
	.setValue('*[name="q"]','webdriverio')
	.click('*[name="btnG"]').pause(1000)
	.getTitle(function(err,title) {
		console.log(title);
	}).end();

WebDriver.io TestingBot Service

WebDriver.io contains a TestingBot service which makes it easy to run tests with WebDriver.io on TestingBot. With this service, WebDriver.io will start a TestingBot Tunnel if required, and send back test meta-data (passed state, name, build-id, ...)


In order to use the service you need to download it from NPM:

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 cucumber
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: 'firefox',
		version: 'latest',
		platform: 'WIN8'
	}],

	/**
	 * test configurations
	 */
	logLevel: 'silent',
	coloredLogs: true,
	screenshotPath: 'screenshots',
	waitforTimeout: 10000,
	framework: 'cucumber',
	services: ['testingbot'],
	user: 'api_key',
	key: 'api_secret',

	reporters: ['dot'],
	reporterOptions: {
		outputDir: './'
	},

	cucumberOpts: {
		require: ['./step-definitions.js']
	}
};

step-definitions.js
var assert = require('assert'),
	tmpResult;

module.exports = function() {
	this.Given(/^I go on the website "([^"]*)"$/, function(url) {
		browser.url(url);
	});

	this.Then(/^should the title of the page be "([^"]*)"$/, function(expectedTitle) {
		var title = browser.getTitle();
		assert.equal(title, expectedTitle, ' title is "'+ title + '" but should be "'+ 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:

~/node_modules/.bin/wdio 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-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: 'firefox',
		version: 'latest',
		platform: 'WIN8'
	}],

	/**
	 * test configurations
	 */
	logLevel: 'silent',
	coloredLogs: true,
	screenshotPath: 'screenshots',
	waitforTimeout: 10000,
	framework: 'mocha',
	services: ['testingbot'],
	user: 'api_key',
	key: 'api_secret',

	reporters: ['dot'],
	reporterOptions: {
		outputDir: './'
	},

	mochaOpts: {
		ui: 'bdd'
	}
};

runner-specs/mocha.test.js
var assert = require('assert');
describe('google page', function() {
	it('should have the right title', function () {
		browser.url('https://www.google.com');
		var title = browser.getTitle();
		assert.equal(title, 'Google');
	});
});


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

~/node_modules/.bin/wdio 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-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: 'firefox',
		version: 'latest',
		platform: 'WIN8'
	}],

	/**
	 * test configurations
	 */
	logLevel: 'silent',
	coloredLogs: true,
	screenshotPath: 'screenshots',
	waitforTimeout: 10000,
	framework: 'jasmine',
	services: ['testingbot'],
	user: 'api_key',
	key: 'api_secret',

	reporters: ['dot'],
	reporterOptions: {
		outputDir: './'
	},

	jasmineNodeOpts: {
		defaultTimeoutInterval: 9999999
	}
};

runner-specs/jasmine.spec.js
describe('google page', function() {
	it('should have the right title', function () {
		browser.url('https://www.google.com');
		var title = browser.getTitle();
		expect(title).toBe('Google');
	});
});


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

~/node_modules/.bin/wdio 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.

Configuring Capabilities

To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote machines. If the test was running on your local machine or network, you can simply change your existing test like this:


Before
// wdio.conf.js
export.config = {
  // ...
  services: ['selenium-standalone'],
  // ...
};

After
// wdio.conf.js
export.config = {
	// ...
	services: ['testingbot'],
	user: process.env.TB_KEY,
	key: process.env.TB_SECRET,
	tbTunnel: true,
	// ...
};


Specifying the operating system, browser and version

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


To see how to do this, please select a combination of browser, version and platform in the drop-down menus below.


1. Select a Platform
2. Select a Browser


Reporting Test Results

If you are using the wdio-testingbot-service then your tests will automatically report back meta-data to TestingBot (like test success, name, stacktrace, ...)

Testing Internal/Staged 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 Webdriver.io test with our Tunnel:


1. Adjust your wdio.conf.js configuration to use tbTunnel: true.
The wdio-testingbot-service will automatically download and use the tunnel for your tests.


wdio.conf.js
exports.config = {
	services: ['testingbot'],
	user: 'api_key',
	key: 'api_secret',
	tbTunnel: true
};

Parallel Testing

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.


Queueing

Every plan we provide comes with a limit of concurrent VMs (how many tests you can run in parallel).
For example: if you have a plan with 5 concurrent VMs, it is possible to start more tests. TestingBot will queue the additional tests and run the tests as soon as slots become available.


To run tests in parallel, you can use WebDriver.io's MultiRemote feature where you specify multiple desired capabilities for your tests.

Other Options

We offer many other test options, for example: disable video recording, specifying a custom Firefox Profile, loading Chrome/Firefox/Safari extensions, running an executable before your test starts, uploading files, ...
See our list of test options for a full list of options to customize your tests.

Pick a NodeJS test framework

  • Webdriver.io

    Webdriver/Selenium 2.0 javascript bindings for NodeJS.

  • 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.js 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.