Playwright Browser Automation Script
By Harper Nguyen · Published · Updated
A Playwright script for a browser task you need to repeat, with stable selectors, proper waits and screenshots or traces kept as proof.
Tags: coding, productivity
Prompt template
## Playwright Browser Automation Script Write a Playwright script for a repeatable browser task. - Task in plain words: [textarea: What the script should do from start to finish] - Start URL: [text: Address of the first page] - Language: [dropdown: TypeScript, JavaScript, Python] - Login needed: [toggle: Yes, No] - Page structure notes: [textarea: Button labels or roles or HTML snippets that matter] - Evidence to keep: [multi: Screenshots, Trace, Video, Text log, Downloaded file] Prefer role and label locators over CSS paths, since they survive redesigns. Never use fixed sleeps: wait on a visible element, a URL change or a network response that proves the step finished. Read credentials from environment variables, and say which names to set, without ever hard-coding a value. Break the task into named steps so a failure shows which step broke. After each step that changes the page, assert one thing that must now be true. Save the chosen evidence into an output folder named by date. Retry only the steps that are safe to repeat and make the script exit with a non-zero code on any failed assertion. Return the full script, the command to run it, the environment variables it needs, and a short list of the places most likely to break.