Skip to main content

Runners

Types of Runners

There are two types of runners:

ClassicRunner

ClassicRunner is used when the screenshot is taken by the SDK itself.

const {ClassicRunner} = require('@applitools/eyes-playwright')
const runner = new ClassicRunner()

For a complete list of methods and parameters, see ClassicRunner class.

VisualGridRunner

VisualGridRunner is used when the screenshot is taken by the Ultrafast grid.

const {VisualGridRunner} = require('@applitools/eyes-playwright')
const runner = new VisualGridRunner(concurrentSessions)
  • concurrentSessions represents the number of visual tests that are allowed to run at the same time. Default: 1.

For a complete list of methods and parameters, see VisualGridRunner class.

Purpose of runners

There are two purposes for using runners:

Use the Ultrafast grid

This is done simply by specifying the VisualGridRunner. Browsers are specified by using the Configuration API. For example:

const {Eyes, VisualGridRunner, BrowserType, DeviceName} = require('@applitools/eyes-playwright')
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)

Manage tests across multiple Eyes instances

If you decide to create more than one instance of Eyes in your tests (for example, if you run new Eyes() in beforeEach test hooks), the runner provides a method called getAllTestResults for collecting test results across all eyes instances.

Example

const {Eyes, ClassicRunner, StitchMode} = require('applitools/eyes-playwright')
const runner = new VisualGridRunner(10)

async function runTest(url, ...browsers) {
await page.goto(url)
const eyes = new Eyes(runner)
const configuration = eyes.getConfiguration()
configuration.addBrowsers(...browsers)
eyes.setConfiguration(configuration)
await eyes.open(page, appName, testName, viewportSize)
await eyes.check(undefined, Target.window().fully())
eyes.close()
}

async function collectResults() {
const testResultsSummary = await runner.getAllTestResults()
for (const testResultContainer of testResultsSummary) {
const testResults = testResultContainer.getTestResults()
console.log(formatTestResults(testResults)) // see the Recipes section below for the implementation of this function
}
}

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)

This code example runs two visual tests in parallel on two websites, using a specific configuration for each URL.

To achieve this, multiple Eyes instances are used, but in order to wait for all test results, the code calls runner.getAllTestResults. It then iterates through the results and print out a formatted summary.