#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Playwright Interview Q&A · #25

How can you record tests in Playwright?

By Uncodemy Editorial Team · Updated 16 Nov 2026

You can record a test by using the site yourself while Playwright watches. The recorder is called codegen. Run one command, click through your flow in the browser window that opens, and Playwright writes the matching test code live in a second window. It is the quickest way for a manual tester to produce a first script, and for anyone to discover good locators on an unfamiliar page.

Step 1: start the recorder

npx playwright codegen https://demo.example.com

Two windows open: a browser, and the Playwright Inspector showing code. Each click, fill or navigation you make appears as a line of code. By default the code is a Playwright Test file in TypeScript/JavaScript; --target switches to Python (python-pytest), Java (java-junit), C# and other flavours.

Step 2: add assertions while you record

A recording that only clicks proves nothing. The Inspector toolbar has assertion tools: choose "assert visibility", "assert text" or "assert value", then click an element. Codegen writes an expect(...) line for it. Add at least one assertion at the end of every flow, on the thing the user actually cares about.

Step 3: save and tidy the code

Copy the code from the Inspector, or write it straight to a file with -o tests/enquiry.spec.ts. A recorded enquiry flow, after a short clean-up, could look like this:

// tests/enquiry.spec.ts
import { test, expect } from '@playwright/test';

test('visitor can send a course enquiry', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('link', { name: 'Software Testing' }).click();
  await page.getByRole('button', { name: 'Enquire now' }).click();
  await page.getByLabel('Full name').fill('Neha');
  await page.getByLabel('Phone').fill('9999999999');
  await page.getByRole('button', { name: 'Submit' }).click();
  await expect(page.getByText('Thank you')).toBeVisible();
});

The clean-up usually means: replace the full start URL with '/' and set baseURL in the config, rename the test to say what it proves, delete accidental clicks, and move repeated steps into a fixture or page object (see fixtures in Playwright). The names and labels above are placeholders.

Useful codegen flags

FlagUse
--device="iPhone 13"Record with mobile emulation
--viewport-size="1280,720"Fix the window size
--save-storage=auth.jsonSave cookies and storage at the end, for example after logging in
--load-storage=auth.jsonStart the recording already logged in
--lang="hi-IN", --timezone="Asia/Kolkata"Record with a locale and time zone
--test-id-attribute=data-qaPrefer your team's test-id attribute in locators
-b webkitRecord in WebKit or Firefox instead of Chromium

Run npx playwright codegen --help to see the full list for your installed version.

Other ways to record

Limits of recorded tests

Want to master Playwright hands-on?

Join Uncodemy's Playwright Automation Testing Course in Noida — Dedicated Placement Support.

Explore the Course →