Calmcode - playwright: introduction

Introduction to Playwright

1 2 3 4 5 6 7 8 9

Imagine that you're working on a website that uses a Python backend. This website might have a backend, which can be tested directly with Pytest but that won't be enough if you'd like to ensure that the front-end behaves as expected. Preferably, you'd like to test the final product that the user sees. That means that you'd like to have a tool that can simulate a browser and can run commands on your behalf.

Playwright is a modern tool for exactly this. It has ports for Javascript, Java and more. But in this series of videos we will use the Python API and show how it can run user behavior and help you write good tests for your front-end.

Install

You can install playwright with pip.

pip install --upgrade pip
pip install playwright

However, this will only install the Python dependencies. You'll also need to install headless browsers that playwright can interact with. These can be installed via:

playwright install

Be warned though. This installation can take a few minutes. If you want to speed things up you can also choose to only install a subset of the available browsers.

playwright install firefox chrome