Runners
Types of runners
Runners are used to manage multiple Eyes sessions. There are the following types of runners:
ClassicRunner
This runner is used when the SDK itself captures the screenshots.
const { ClassicRunner } = require('@applitools/eyes-webdriverio');
const runner = new ClassicRunner();
VisualGridRunner
This runner is used when the screenshots are captured using the Ultrafast Grid.
const { VisualGridRunner } = require('@applitools/eyes-webdriverio');
const runner = new VisualGridRunner(concurrentSessions);
The concurrentSessions
parameter represents the number of visual tests that can run simultaneously. The default value is 1
.
Running Tests with the Ultrafast Grid
The Ultrafast Grid allows you to run tests across multiple browsers and devices. To use the Ultrafast Grid, you need to specify the VisualGridRunner
and list the required browsers in the Configuration
API.
Example
const { Eyes, VisualGridRunner, BrowserType, DeviceName } = require('@applitools/eyes-webdriverio');
const eyes = new Eyes(new VisualGridRunner());
const configuration = eyes.getConfiguration();
configuration.addBrowser({ width: 1200, height: 800, name: BrowserType.CHROME });
configuration.addBrowser({ width: 1200, height: 800, name: BrowserType.FIREFOX });
configuration.addBrowser({ width: 1200, height: 800, name: BrowserType.SAFARI });
configuration.addBrowser({ width: 1200, height: 800, name: BrowserType.EDGE });
configuration.addBrowser({ width: 1200, height: 800, name: BrowserType.IE_11 });
configuration.addBrowser({ deviceName: DeviceName.Galaxy_S9_Plus });
eyes.setConfiguration(configuration);
Managing Tests Across Multiple Eyes Instances
If you create multiple instances of Eyes in your tests (for example, if you run new Eyes()
in beforeEach
test hooks), the runner provides a method called getAllTestResults
to collect test results across all Eyes instances.
Example
const {
Eyes,
ClassicRunner,
StitchMode,
} = require("applitools/eyes-webdriverio");
const runner = new VisualGridRunner(10);
async function runTest(url, ...browsers) {
await driver.get(url);
const eyes = new Eyes(runner);
const configuration = eyes.getConfiguration();
configuration.addBrowsers(...browsers);
eyes.setConfiguration(configuration);
await eyes.open(driver, appName, testName, viewportSize);
await eyes.check(undefined, Target.window().fully());
await eyes.closeAsync();
}
async function collectResults() {
const testResultsSummary = await runner.getAllTestResults();
for (const testResultContainer of testResultsSummary.getAllResults()) {
const testResults = testResultContainer.getTestResults();
console.log(formatTestResults(testResults));
}
}
Promise.all([
runTest(
'https://example.org',
{ width: 1200, height: 800, name: BrowserType.CHROME },
{ width: 1200, height: 800, name: BrowserType.FIREFOX }
),
runTest(
'https://applitools.com',
{ deviceName: DeviceName.Galaxy_S9_Plus },
{ deviceName: DeviceName.iPhone_X }
),
]).then(collectResults);
In this code example, two visual tests are run in parallel on two different websites. Each URL has a specific configuration. To achieve this, multiple Eyes instances are used. To wait for all test results, the code calls runner.getAllTestResults
, which provides a summary of the results by iterating through them and printing a formatted summary.