AI assistant workflows
Draft Playwright PHP tests with a coding assistant, then verify selectors, API calls, and generated code against the documentation and local tests.
AI assistants can help draft tests, migrate selectors, and explain failures. They should not be the source of truth for Playwright PHP behavior. Use the API reference, guides, and local tests to verify generated code.
This page is a workflow example, not a runnable PHP script. It shows how to ask for Playwright PHP code without accepting invented APIs or JavaScript-shaped answers.
Good tasks for an assistant
- Draft a PHPUnit browser test from an existing user flow.
- Convert brittle CSS selectors to role, label, or test-id locators.
- Summarize a trace failure into a short debugging checklist.
- Generate a first version of CI steps from the commands used locally.
- Compare JavaScript Playwright examples with the PHP API and flag the differences.
Guardrails
- Ask for PHP code, not JavaScript with renamed variables.
- Prefer
Playwright::chromium(),locator(), and web-firstexpect()assertions from the local docs. - Treat any unverified method name as a draft until it appears in the API reference.
- Run the generated test before accepting it.
- Keep credentials, cookies, and production URLs out of prompts.
Prompt template
Write a PHPUnit browser test for this flow using Playwright PHP.
Use semantic locators first, then test ids, then CSS only when necessary.
Do not use sleeps. Use web-first assertions.
Return only PHP code and list any API calls you are uncertain about.
Validation checklist
vendor/bin/phpunit --filter MyBrowserTest
Expected result: PHPUnit passes without invented methods or JavaScript-only APIs. On failure, inspect the screenshot or trace path configured by the project, usually under var/playwright-artifacts/.
If the assistant used an API that does not exist, replace it with a documented method before editing the flow logic.
Check every generated method name against the API reference, then keep the useful test pattern and discard any speculative code.
What not to ask for
Do not ask an assistant to invent package architecture, public namespaces, or release policy from scratch. Those decisions belong in the architecture docs and ADRs, then in code review.
Go next
- Learn the API shape: Core concepts
- Translate examples safely: Converting from JavaScript
- Debug generated tests: Debugging