Skip to main content

Playwright Python overview

This SDK allows you to work with Applitools Eyes using Playwright Python.

For information about installing and configuring this SDK, see Testing web apps in Python using Playwright on the Applitools Tutorial site.

Getting started

To get started with this SDK, you need to set the following:

Entering the Applitools API key

To authenticate via the Applitools server and run tests, you need to set the environment variable APPLITOOLS_API_KEY to the API key provided from Applitools Eyes. For details how to retrieve your API key, see the Applitools documentation.

Entering the API Key on Linux or a Mac

export APPLITOOLS_API_KEY=<API_key>

Entering the API Key on Windows

set APPLITOOLS_API_KEY=<API_key>

Eyes server URL

If the Eyes server is not deployed in https://eyes.applitools.com, you need to set the Server URL in the environment variable APPLITOOLS_SERVER_URL before running tests.

The server URL of your Applitools Eyes dashboard is in the format https://<MY_COMPANY>.applitools.com

Entering the server URL on Linux or a Mac

export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>

Entering the server URL on Windows

set APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>

Recommended practice for using the SDK

A test in Applitools Eyes always starts with a eyes.open call and ends with eyes.close. The steps in the test are calls to eyes.check between eyes.open and eyes.close calls.

A test is structured as following:

eyes.open
[step 1]
[step 2]
...
eyes.close

Common methods

Eyes constructor

Creates an instance of Eyes, which then exposes methods to run and configure visual tests.

from applitools.playwright import Eyes, ClassicRunner

runner = ClassicRunner()
eyes = Eyes(runner)
  • runner - A runner instance which manages tests across multiple Eyes instances. The runner can be an instance of either a ClassicRunner or a VisualGridRunner. For more information, see Runners.

open

Creates an Eyes test. This will start a session with the Applitools server.

from applitools.common import RectangleSize

eyes.open(page, "App name", "Test name", RectangleSize(1280, 800))

Visual tests and baselines

By using the open, check, and close methods on Eyes, you are creating visual tests in Applitools Eyes. A visual test is a sequence of screenshots, compared with a baseline. The baseline is also a sequence of screenshots. The specific baseline to compare against is found by using the values for:

  • Browser
  • Operating system
  • App name
  • Test name
  • Viewport size

The baseline is created automatically when running a test with specific values for these 5 parameters for the first time. For example, if you run a test with Chrome on OS X and specify the app name, test name and viewport size via eyes.open(page, "some app", "some test", RectangleSize(1280, 800)), the first time the test runs with these parameters, a baseline will be created. Any subsequent execution with the same values will compare screenshots against this baseline. The test will actually be created after running eyes.close, and the results of the test are returned as a TestResults object.

For more information, see How Eyes compares checkpoints and baseline images

Batches

You can aggregate tests that are run in different processes, or in different Eyes instances, under the same batch. This is done by providing the same batch ID to these tests.

For more information, see How to organize your tests with batches.

check

Generates a screenshot of the current page and add it to the Applitools Test.

Syntax

eyes.check(check_settings);

For a description of common actions with this class, see check Settings

close

Closes the Eyes test and checks that all screenshots are valid.

It is important to call this at the end of each test, symmetrically to open, or in afterEach(). See Recommended practice for using the SDK.

test_results = eyes.close(raise_ex);
  • raise_ex - (bool) raise an error if visual differences were found, or if the test failed for any other reason. The default is True.

Return value: TestResults

get_results

Returns TestResults for all tests that were run in an Eyes instance. If the test was run with the Ultrafast Grid, TestResults includes results for all environments. If you call get_results before eyes.close the method aborts the test.

eyes.get_results()

Runners

Used to manage multiple Eyes sessions. There are the following types of runners:

  • ClassicRunner - Used when the screenshot is taken by the SDK itself.

  • VisualGridRunner - Used when the screenshot is taken by the Ultrafast Grid.

For details, see Runners

Logs

Log files are automatically saved in the temp directory of the machine the tests ran on.

By default, the log directory is <os temp directory>/applitools-logs

You can locate it as follows:

  • Mac/Linux: $TMPDIR/applitools-logs/
  • Windows: %Temp%/applitools-logs/

When running the tests remotely, you can specify the path to the logs using the environment variable APPLITOOLS_LOG_DIR=<full path to log_dir>