#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 · #1

What is Playwright?

Playwright is an open-source framework from Microsoft for automating real web browsers. You write a script that opens a page, clicks, types and checks what the user would see, and Playwright runs it in Chromium, Firefox or WebKit (the engine behind Safari). It was first released in 2020 and is used mainly for end-to-end testing of web applications, though it also works for scraping, screenshots and general browser automation.

Official bindings exist for JavaScript/TypeScript, Python, Java and .NET (C#). The JavaScript version ships with its own test runner, @playwright/test, which is what most teams mean when they say "we use Playwright".

Library vs test runner

Interviewers often check whether you know that Playwright has two layers:

LayerWhat it gives you
Browser automation library (playwright)APIs to launch a browser, open pages, find elements, intercept network calls. You manage setup and assertions yourself.
Test runner (@playwright/test)Test files, fixtures such as page and context, web-first assertions with expect, parallel workers, retries, HTML report, traces, screenshots and videos.

In Python the usual pairing is the library plus the pytest-playwright plugin, which provides similar fixtures.

A first test, line by line

Create a project with npm init playwright@latest. It asks a few questions, installs the browsers and writes a sample config. Then add tests/search.spec.ts:

import { test, expect } from '@playwright/test';

test('Get started link opens the installation page', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Find elements the way a user would: by role and visible name
  await page.getByRole('link', { name: 'Get started' }).click();

  // Web-first assertion: retries until it passes or times out
  await expect(page).toHaveURL(/.*intro/);
  await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

What happens when you run it:

  1. The runner starts a browser and gives the test a fresh page inside a new, isolated browser context (no cookies from other tests).
  2. click() waits until the link is visible, stable and enabled before clicking. You do not add sleeps.
  3. Each expect(...) keeps re-checking for up to 5 seconds by default, so a slow page load does not fail the test straight away.
  4. The result is printed in the terminal, for example 1 passed (2.1s) per browser project.

Everyday CLI commands

CommandUse
npx playwright testRun all tests, headless, in every project from the config
npx playwright test --headedShow the browser window
npx playwright test --project=firefoxRun only one browser project
npx playwright test --uiUI mode: watch, time-travel through steps, re-run single tests
npx playwright test --debugOpen the Playwright Inspector and step through
npx playwright codegen https://example.comRecord your clicks and generate test code
npx playwright show-reportOpen the HTML report from the last run

Why teams pick it

If you are coming from Selenium, the Playwright vs Selenium comparison explains the differences in architecture and waiting.

Common beginner mistakes

Next, read about which browsers Playwright supports, or follow the longer beginner guide to Playwright testing.

Want to master Playwright hands-on?

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

Explore the Course →