You can dynamically generate and run tests with Playwright without creating
.spec files. To do this, use the built-in test generator with the
codegen command. Here's how:
codegencommand followed by the URL of the website you want to generate tests for (e.g.,
https://ray.run/). The URL is optional, and you can add it directly into the browser window later.
npx playwright codegen https://ray.run/
Record a test: Perform actions in your browser, and Playwright will generate code for your interactions. It will recommend locators based on the rendered page, prioritizing role, text, and test ID locators.
Generate locators: After recording, click the 'Record' button to stop, and the 'Pick Locator' button will appear. Click it, then hover over elements in your browser window to see the locator highlighted. Click on an element to choose a locator, and copy or fine-tune its code.
Emulate specific conditions: Generate tests using emulation to target specific viewports, devices, color schemes, geolocations, languages, or timezones while preserving the authenticated state if needed.
With Playwright, you can create tests interactively and programmatically from external data using the test generator, making it easier for developers to generate tests without manually creating
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email firstname.lastname@example.org.