Testing web apps in Python using Playwright | Applitools Documentation
Quickstart for Visual Testing with Python and Playwright
This quickstart will show you how to visually test web apps in Python using Playwright. Visual testing can help you catch problems that traditional automation struggles to find.
After preparing your environment, this three-step quickstart should take about 15 minutes to complete.
Step 1: Preparing your environment
You'll need a few things to run this quickstart:
- An Applitools account, which you can register for free.
- A recent version of Python 3.
- A good Python editor like Visual Studio Code or JetBrains PyCharm.
Step 2: Getting your example project
Downloading the example project
The example project is located at https://github.com/applitools/example-playwright-python. Clone this repository to your local machine:
git clone https://github.com/applitools/example-playwright-python.git
cd example-playwright-python
Don't have Git?
Instead of running git clone, you can download the project as a ZIP file and extract it.
Installing the dependencies
The example project uses pip for package management. For Playwright, you must install project dependencies and browsers. Run the following commands:
pip3 install -r requirements.txt
playwright install
Adding Applitools to Another Python Project?
This example project already declares the Applitools Eyes SDK as a dependency. If you want to add the Applitools Eyes SDK into an existing Python environment, run:
pip3 install eyes-playwright
Deciding how to run tests
There are two ways to test the visual snapshots captured by the test:
- Using Applitools Ultrafast Grid for cross-browser testing in the cloud
- Using Applitools Classic runner on your local machine
Walking through the code
All test setup and cleanup is handled by a set of pytest fixtures located at tests/conftest.py.
# Sample code
# --- Add your fixtures and test cases here ---
Step 3: Running your tests
Setting Applitools variables
Before running the visual test, you must find your Applitools API key and set it as an environment variable named APPLITOOLS_API_KEY.
You may set it through your IDE or from the command line:
export APPLITOOLS_API_KEY=<your-api-key> # macOS and Linux
Or on Windows:
set APPLITOOLS_API_KEY=<your-api-key>
Launching visual tests
Run the following command to launch tests:
python3 -m pytest -s -v tests
After your tests run, you should see results in the Eyes Test Manager.
The project contains one visual test case, located at tests/test_acme_bank.py:
# Sample test code
def test_log_into_bank_account(page: Page, eyes: Eyes) -> None:
page.goto("https://demo.applitools.com")
eyes.check(Target.window().fully().with_name("Login page"))
page.locator('id=username').fill('andy')
page.locator('id=password').fill('i<3pandas')
page.locator('id=log-in').click()
eyes.check(Target.window().fully().with_name("Main page"))
Taking the next steps with Applitools
Congratulations on completing this quickstart! There's still much more to learn about visual testing with Applitools, but you're off to a great start.