TestKase
TestKase
|Docs
AutomateBrowserPlaywright

First test in Python

A complete Playwright test in Python you can copy, run, and watch on a real browser.

One file. Copy it, put your access key in, run it, and watch it happen in your dashboard.

What you need

Python 3.8 or newer, and Playwright itself:

pip install playwright

Nothing of ours to install. This is the ordinary Playwright library.

The whole test

# first_test.py
import json
import uuid
from urllib.parse import quote

from playwright.sync_api import sync_playwright

ACCESS_KEY = "xyz_your_access_key_here"
TEST_NAME = "example.com opens"

capabilities = {
    "browserName": "chrome",
    "browserVersion": "latest",
    "testkase:options": {
        "accessKey": ACCESS_KEY,
        "platformName": "windows 11",
        "name": TEST_NAME,
        "build": "first-test",
        "runId": str(uuid.uuid4()),
        "recording": True,
    },
}

with sync_playwright() as p:
    ws = f"wss://hub.testkase.com/playwright?capabilities={quote(json.dumps(capabilities))}"
    browser = p.chromium.connect(ws)

    page = browser.new_page()
    page.goto("https://example.com")

    title = page.title()
    assert "Example Domain" in title, f"wrong title: {title}"
    print("  title:", title)

    browser.close()
    print("PASS ", TEST_NAME)

What each part does

Six things carry the whole file. Read down the middle column and you have its shape.

The partWhat it does
1wss://hub.testkase.com/playwright?capabilities=…Where everything goes. Playwright has no capability argument, so the whole object is URL-encoded onto the connect address.
2accessKeySigns you in. Copy it from the Access key page. There is no username here — the key is the only credential.
3platformNameWhich operating system. Set it. Leave it out and Chrome, Edge and Firefox fall back to linux, which no machine of ours runs, so the session is refused.
4recording: trueSays what to keep. name is how you will recognise the session in a list; recording is the video, and you get none unless you ask. Every option.
5p.chromium.connect(ws)Ordinary Playwright from here on. Every command behaves exactly as it does locally — we only carry it to the browser and back. You call chromium.connect whichever brand you asked for; the address decides what you get.
6browser.close()Ends the session and frees the machine. Forget it and the session runs until a timeout stops it — which you are paying for.

Run it

python first_test.py

The browser opens on our machines, not yours. Open your dashboard while it runs and the session is there live; when it ends, the video is on it.