WebDriverIO Automated App Testing
First, make sure you have installed NodeJS. If you haven't, you can easily install it by downloading NodeJS from https://nodejs.org/en/download/
See our WebdriverIO examples repository for some examples on how to use WebdriverIO with TestingBot.
Installation
TestingBot has its own WebDriverIO 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 i --save-dev @wdio/cli @wdio/local-runner
You are now ready to run a WebDriver test with NodeJS on our grid.
WebDriverIO TestingBot Service
WebDriverIO contains a TestingBot service which makes it easy to run tests with WebDriverIO on TestingBot. With this service, WebDriverIO 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
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.jsexports.config = {
/**
* specify test files
*/
specs: [
'./runner-specs/mocha.test.js'
],
/**
* capabilities
*/
capabilities: [{
name: 'My First App Test',
deviceName: 'Pixel 8',
platformName: 'Android',
version: '14.0',
app: 'https://testingbot.com/appium/sample.apk'
}],
/**
* test configurations
*/
logLevel: 'silent',
coloredLogs: true,
screenshotPath: 'screenshots',
waitforTimeout: 10000,
connectionRetryTimeout: 480000,
framework: 'mocha',
services: [
['testingbot']
],
user: 'api_key',
key: 'api_secret',
reporters: ['dot'],
reporterOptions: {
outputDir: './'
},
mochaOpts: {
ui: 'bdd'
}
};
const assert = require('assert')
describe('calculator', function() {
it('should calculate a sum', async () => {
const inputA = await $('~inputA')
await inputA.waitForDisplayed(5000)
await inputA.click()
try {
await inputA.addValue('10')
} catch (e) {}
const inputB = await $('~inputB')
await inputB.waitForDisplayed(5000)
await inputB.click()
try {
await inputB.addValue('5')
} catch (e) {}
const sumElement = await $('~sum')
const sum = await sumElement.getText()
assert.equal(sum, '15') // 10 + 5
})
})
Now we can run this mobile app test on TestingBot. The test will do a simple sum calculation and verify if the calculation was correct.
To start the test, please run this command:
~/node_modules/.bin/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.
Uploading Your App
Please see our Upload Mobile App documentation to find out how to upload your app to TestingBot for testing.
Specify Browsers & Devices
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:export.config = {
// ...
services: ['selenium-standalone'],
// ...
};
export.config = {
// ...
services: [
['testingbot']
],
user: process.env.TB_KEY,
key: process.env.TB_SECRET,
// ...
};
To let TestingBot know on which device you want to run your test on, you need to specify the deviceName
, version
, platformName
and other optional options in the capabilities field.
To see how to do this, please select a combination of device type and device name in the drop-down menus below.
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 WebdriverIO 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.
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: [{
name: 'My First App Test',
deviceName: 'Pixel 8',
platformName: 'Android',
version: '14.0',
app: 'https://testingbot.com/appium/sample.apk'
},
{
name: 'My Second App Test',
deviceName: 'Pixel 9',
platformName: 'Android',
version: '15.0',
app: 'https://testingbot.com/appium/sample.apk'
}]
};
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 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 for a long time.
Solution: You can try adding the
connectionRetryTimeout
in your WebDriverIO configuration with a high enough value:CopyconnectionRetryTimeout: 480000
Preparing your App
You do not need to install any code or plugin to run a test.
Below are some things that are necessary to successfully run a mobile test:
- Please supply the URL to your
.apk
or.aab
file.
Important: the.apk
file needs to be a x86 build (x86 ABI) for Android emulators.
- Please supply the URL to an
.ipa
file.
- Please supply the URL to a
.zip
file that contains your.app
-
The
.app
needs to be an iOS Simulator build:
- Create a Simulator build:Copy
xcodebuild -sdk iphonesimulator -configuration Debug
- Zip the
.app
bundle:Copyzip -r MyApp.zip MyApp.app
- Create a Simulator build:
Additional Options
Appium provides a lot of options to configure your test.
Some important options that might help:
For Android:- appActivity and appPackage: by default, Appium will try to extract the main Activity from your apk. If this fails, you can supply your own with these options.
- chromeOptions: additional chromedriver options you can supply.
- otherApps: a JSON array of other apps that need to be installed, in URL format.
-
locale: the language of the simulator/device (ex:
fr_CA
)This sets the locale on the entire device/simulator, except on physical iOS devices. For real iOS devices, we will pass
-AppleLocale
as argument to the app. - newCommandTimeout: How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session