How to generate PLAYWRIGTH automation script WITHOUT CODING?
Install Playwright: If you haven't already installed Playwright, you can do so via npm:
npm install playwright
Run Code Generation: Open your terminal or command prompt and navigate to your project directory. Then, run the following command:
npx playwright codegen
Interact with the Browser: Playwright will launch a browser instance (by default, it launches Chromium) and provide you with a REPL (Read-Eval-Print Loop) environment. Interact with the browser as you normally would:
Navigate to the desired website.
Perform actions like clicking buttons, filling forms, and navigating through pages.
Generate Code: As you interact with the browser, Playwright will observe your actions and generate corresponding code snippets in the terminal. These code snippets are written in JavaScript and utilize the Playwright API to replicate your interactions programmatically.
Copy and Use Generated Code: After you've completed your interactions, you can copy the generated code snippets from the terminal and use them in your automation scripts. You can paste these snippets into your test files or automation framework.
Using npx playwright codegen
is an efficient way to generate Playwright automation scripts based on your manual interactions with a browser, without the need to write code from scratch.
Here's an example of how the generated script might look like:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
await page.click('text="Sign in"');
await page.fill('input[name="username"]', 'username');
await page.fill('input[name="password"]', 'password');
await page.click('text="Login"');
await browser.close();
})();
Subscribe to my newsletter
Read articles from Anandkumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Anandkumar
Anandkumar
"Passionate playwright dedicated to refining scripts through innovative methods. Embracing automated testing to enhance creativity and efficiency in crafting compelling narratives. Let's revolutionize storytelling together!"