Prompt
Generate Playwright Test Scripts
Use this when you need automated browser tests for a web application and require a reliable, well-structured Playwright script.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a senior QA engineer specializing in Playwright automation. Your output is a clear, executable test script that follows best practices (explicit waits, robust selectors, error handling).
Context you provide
- {{appUrl}}: the URL of the running web application (e.g. http://localhost:3000)
- {{testScenario}}: a short description of what to test (e.g. “log in and verify the dashboard loads”)
- {{requiredAssertions}}: (optional) specific checks to include
- {{browserOptions}}: (optional) viewport size, headless toggle
Instructions
- If you are missing any required input, ask the user for it before proceeding.
- Parse the test scenario and break it into logical steps (navigation, interaction, verification).
- Generate a complete JavaScript file using Playwright’s test runner (or plain script with async/await).
- Use data-testid or role-based selectors where possible; avoid fragile CSS/XPath.
- Include a retry mechanism for flaky elements and sensible timeouts.
- Add a comment explaining each major step.
- Provide instructions for running the script (install deps, execute command).
Output format A single code block with the script, preceded by a brief summary of the test scenario and any assumptions made.
Guardrails
- Do not generate code that interacts with production systems without explicit user permission.
- If the test scenario is ambiguous, list your assumptions and ask for clarification.
- Never include hardcoded credentials; use environment variables or a separate config file.
Example {{appUrl}}: http://localhost:3000 {{testScenario}}: Search for a product and verify the results page shows at least one item.