Runners
Types of runners
There are two types of runners:
ClassicRunner
ClassicRunner
is used when the screenshot is taken by the SDK itself.
ClassicRunner classicRunner = new ClassicRunner();
VisualGridRunner
VisualGridRunner
is used when the screenshot is taken by the Ultrafast grid.
VisualGridRunner visualGridRunner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));
concurrentSessions
represents the number of visual tests that are allowed to run at the same time. Default:1
.
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:
Eyes eyes = new Eyes(new VisualGridRunner());
Configuration configuration = eyes.getConfiguration();
configuration
.addBrowser(1400, 700, BrowserType.CHROME)
.addBrowser(1200, 900, BrowserType.FIREFOX)
.addBrowser(1200, 900, BrowserType.SAFARI)
.addBrowser(1200, 900, BrowserType.EDGE_CHROMIUM)
.addBrowser(1200, 900, BrowserType.IE_11)
;
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
Playwright playwright;
Browser browser;
BrowserContext context;
@Test
public void testWithGetAllTestResults() {
playwright = Playwright.create();
browser = playwright.chromium().launch();
context = browser.newContext();
Page page = context.newPage();
page.navigate("https://applitools.com");
VisualGridRunner runner = new VisualGridRunner(10);
Eyes eyes = new Eyes(runner);
eyes.open(page, "applitools.com website", "My first Playwright test!");
eyes.check("home page", Target.window().fully());
eyes.closeAsync();
TestResultsSummary testResultSummary = runner.getAllTestResults();
for (TestResultContainer testResultContainer: testResultSummary.getAllResults()) {
TestResults testResults = testResultContainer.getTestResults();
System.out.println(formatTestResults(testResults));
}
}
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 testResultContainer.getTestResults
. It then iterates through the results and prints out a formatted summary.