Playwright (Python)
Overview
The playwright-python plugin generates Python code using the Playwright library for browser automation and testing.
within Browser (plugin: playwright-python, type: browser) go to "https://example.com"Types
browser
The main browser context. Launches a Chromium browser and creates a new page.
Type Modifiers:
| Modifier | Type | Description |
|---|---|---|
url | quoted | Initial URL to navigate to on launch |
headless | quoted | Run browser in headless mode |
Patterns:
| Pattern | Description |
|---|---|
go to <url> | Navigate to URL |
click <target> | Click element by selector |
type <text> into <target> | Type text into input element |
see a/an/any/no <target> | Assert element visibility or count |
wait for <target> | Wait for element to appear |
expect failure | Expect code block to raise an exception |
Pattern Modifiers:
| Pattern | Modifier | Type | Description |
|---|---|---|---|
go to | timeout | quoted | Navigation timeout |
click | timeout | quoted | Click timeout |
type | timeout | quoted | Type timeout |
see | text | quoted | Text content to match |
wait for | timeout | quoted | Wait timeout |
wait for | state | quoted | Wait state (e.g., “visible”, “attached”) |
expect failure | error | quoted | Expected exception type |
expect failure | capture | quoted | Variable name to capture exception |
element
A scoped element context for targeting nested elements. Inherits patterns from browser type.
Type Modifiers:
| Modifier | Type | Description |
|---|---|---|
id | quoted | Select by element ID |
class | quoted | Select by CSS class |
testid | quoted | Select by data-testid attribute |
label | quoted | Select by accessible label |
within Login Form (type: element, testid: "login-form") type "user@example.com" into "Email"Patterns:
The element type supports the same patterns as browser: click, type, see, wait for, and expect failure.
failure_block
A passthrough block used inside expect failure to contain actions that should raise an exception.
Pattern Details
see
The see pattern requires a quantifier to specify the expected element count:
| Quantifier | Assertion |
|---|---|
a or an | Exactly one element exists |
any | At least one element is visible |
no | Zero elements exist |
see a "Submit Button"see no "Error Message"see any "Product Card"expect failure
Wrap actions that should raise an exception. Useful for testing error handling.
expect failure (error: "TimeoutError", capture: "exc_info") click "Nonexistent Element"Generated code uses pytest.raises context manager.
Example
vanya 0.1"Complete checkout flow"
within Browser (plugin: playwright-python, type: browser, headless: "true") go to "https://shop.example.com" click "Add to Cart" click "Checkout" within Shipping Form (type: element, testid: "shipping-form") type "123 Main St" into "Address" type "10001" into "ZIP" click "Place Order" see a "Order Confirmation" see no "Error Message"Generated Code
The above example generates Python code similar to:
ctx = playwright.chromium.launch().new_page()ctx.goto("https://shop.example.com")ctx.locator("Add to Cart").click()ctx.locator("Checkout").click()ctx = parent.locator("[data-testid='shipping-form']")ctx.locator("Address").fill("123 Main St")ctx.locator("ZIP").fill("10001")ctx.locator("Place Order").click()expect(ctx.locator("Order Confirmation")).to_have_count(1)expect(ctx.locator("Error Message")).to_have_count(0)