What is @wdio/runner?
@wdio/runner is a core package of the WebdriverIO test framework. It is responsible for running the test suite, managing the lifecycle of the WebDriver sessions, and handling the execution of test scripts. It provides a robust and flexible environment for running automated tests across different browsers and devices.
What are @wdio/runner's main functionalities?
Running Test Suites
This code demonstrates how to run a test suite using the @wdio/runner package. It sets up the configuration for the test run, including the test specs, browser capabilities, log level, test framework, and reporters. The `run` function is then called with the configuration, and the process exits with the appropriate exit code based on the test results.
const { run } = require('@wdio/runner');
const config = {
specs: ['./test/specs/**/*.js'],
capabilities: [{ browserName: 'chrome' }],
logLevel: 'info',
framework: 'mocha',
reporters: ['spec'],
};
run(config).then(
(exitCode) => process.exit(exitCode),
(error) => {
console.error('Error:', error);
process.exit(1);
}
);
Managing WebDriver Sessions
This example shows how to manage WebDriver sessions using the @wdio/runner package. The configuration specifies the use of Firefox as the browser and Jasmine as the test framework. The `run` function handles the lifecycle of the WebDriver sessions, ensuring that they are properly started and terminated during the test run.
const { run } = require('@wdio/runner');
const config = {
specs: ['./test/specs/**/*.js'],
capabilities: [{ browserName: 'firefox' }],
logLevel: 'info',
framework: 'jasmine',
reporters: ['dot'],
};
run(config).then(
(exitCode) => process.exit(exitCode),
(error) => {
console.error('Error:', error);
process.exit(1);
}
);
Customizing Test Execution
This code sample demonstrates how to customize test execution using the @wdio/runner package. The configuration includes additional options for the Mocha framework, such as setting a custom timeout for the tests. The `run` function executes the tests with the specified configuration, allowing for flexible and tailored test runs.
const { run } = require('@wdio/runner');
const config = {
specs: ['./test/specs/**/*.js'],
capabilities: [{ browserName: 'chrome' }],
logLevel: 'debug',
framework: 'mocha',
reporters: ['spec'],
mochaOpts: {
timeout: 60000,
},
};
run(config).then(
(exitCode) => process.exit(exitCode),
(error) => {
console.error('Error:', error);
process.exit(1);
}
);
Other packages similar to @wdio/runner
selenium-webdriver
The selenium-webdriver package is a popular tool for browser automation. It provides a set of bindings for WebDriver, allowing you to write tests in various programming languages. Compared to @wdio/runner, selenium-webdriver offers more direct control over WebDriver sessions but requires more boilerplate code to set up and manage tests.
cypress
Cypress is an end-to-end testing framework that aims to make testing fast, easy, and reliable. It provides a rich set of features for writing and running tests, including time travel, real-time reloads, and automatic waiting. Unlike @wdio/runner, Cypress does not use WebDriver and instead runs directly in the browser, which can lead to faster and more reliable tests but may have limitations in terms of browser support.
testcafe
TestCafe is a modern end-to-end testing framework that does not require WebDriver. It supports multiple browsers and provides a simple API for writing tests. TestCafe handles the test execution and browser management internally, making it easier to set up and run tests compared to @wdio/runner. However, it may not offer the same level of flexibility and control as WebdriverIO.