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.

from applitools.playwright import ClassicRunner

classic_runner = ClassicRunner();

VisualGridRunner

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

from applitools.playwright import VisualGridRunner, RunnerOptions

concurrent_sessions = 5
visual_grid_runner = VisualGridRunner(RunnerOptions().test_concurrency(concurrent_sessions));
  • concurrent_sessions represents the number of visual tests that are allowed to run at the same time. Default: 5.

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:

from applitools.playwright import BrowserType

eyes = Eyes(VisualGridRunner());
configuration = eyes.configuration
configuration.add_browser(1400, 700, BrowserType.CHROME)
configuration.add_browser(1200, 900, BrowserType.FIREFOX)
configuration.add_browser(1200, 900, BrowserType.SAFARI)
configuration.add_browser(1200, 900, BrowserType.EDGE_CHROMIUM)
configuration.add_browser(1200, 900, BrowserType.IE_11)

Manage tests across multiple Eyes instances

If you decide to create more than one instance of Eyes in your tests, the runner provides a method called get_all_test_results for collecting test results across all eyes instances.

Example

Playwright Python
from playwright.sync_api import sync_playwright
from applitools.playwright import Eyes, VisualGridRunner, BrowserType, Target, \
RunnerOptions
from concurrent.futures import ThreadPoolExecutor


def playwright_test_with_get_all_test_results(runner, url, test_name):
with sync_playwright() as playwright:
eyes = Eyes(runner)
configuration = eyes.get_configuration()
configuration.add_browser(1400, 700, BrowserType.CHROME)
configuration.add_browser(1200, 900, BrowserType.FIREFOX)
configuration.add_browser(1200, 900, BrowserType.SAFARI)
configuration.add_browser(1200, 900, BrowserType.EDGE_CHROMIUM)
configuration.add_browser(1200, 900, BrowserType.IE_11)
eyes.set_configuration(configuration)

page = playwright.chromium.launch().new_context().new_page()
eyes.open(page, "Applitools websites", test_name)
page.goto(url)
eyes.check("home page", Target.window().fully())
eyes.close_async()


with sync_playwright() as playwright:
runner = VisualGridRunner(RunnerOptions().test_concurrency(10))
with ThreadPoolExecutor(2) as parallel_executor:
demo_page_test = parallel_executor.submit(
playwright_test_with_get_all_test_results,
runner, "https://demo.applitools.com", "Appitools Demo page"
)
playwright_test_page = parallel_executor.submit(
playwright_test_with_get_all_test_results,
runner, "https://playwright.dev/python/docs/intro", "Playwright docs"
)
# Wait for all threads to finish
demo_page_test.result()
playwright_test_page.result()
# Wait for all renderings and checks to finish
test_results_summary = runner.get_all_test_results(False)
print("The test results are:")
for results_container in test_results_summary:
print(
results_container.browser_info.browser,
results_container.test_results.name,
results_container.test_results.status
)

This code example runs two visual tests in parallel on two websites, using a specific configuration with five different browsers for each URL. Ten tests in total are performed in parallel.

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