Playwright & PyTest

To use PyTest with Playwright, we'll need a Python library that automates via Playwright.
Microsoft's playwright-python library provides a Python library which does Automation via Playwright.

To get started, please install these packages:

pip install playwright pytest
python -m playwright install

Now you're ready to use Python with Playwright. You can take a look at the playwright-python examples on how to do this.


To get started, please see this simple example below.
This will start a new Chrome browser in the TestingBot browser grid, and allow PyTest to control the browser via Playwright.

import pytest
from playwright import sync_playwright

def browser():
  pw_context = sync_playwright()
  pw = pw_context.__enter__()
  browser = getattr(pw, "chromium").connect(wsEndpoint='wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=chrome&browserVersion=latest')
  browser._close = browser.close

  def _handle_close() -> None:
    pw_context.__exit__(None, None, None)

  browser.close = _handle_close

  return browser

def test_title(browser):
  page = browser.newPage()
  assert page.title() == 'Cross Browser Testing and Mobile App Testing | TestingBot'

This example will open a Chrome browser, navigate to the TestingBot homepage and verify the page's title.

Parallel Testing with Pytest

One of the great advantages of our service is that you can run multiple tests simultaneously (in parallel).
This drastically shortens the total duration of your test suite, as multiple tests will run concurrently.

We recommend using pytest-parallel.