Skip to contentমূল লেখায় যান

Step 16 · SDET roadmapধাপ 16 · SDET roadmap

UI Automation with Playwright

This page explains how a test finds an element and waits for it, walks you through a first test on a demo app, and shows how a tester keeps a growing suite readable and easy to debug.

8 min read8 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 12 sources12টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Playwright waits, then clicksPlaywright অপেক্ষা করে, তারপর ক্লিক করে

Watch a click wait for a button to become ready, and an assertion retry up to 5 seconds.দেখুন একটা ক্লিক বাটন তৈরি হওয়া পর্যন্ত অপেক্ষা করে, আর একটা assertion ৫ সেকেন্ড পর্যন্ত আবার চেষ্টা করে।

2 min2 মিনিট8 steps8টি ধাপ
  • Matchesমিল2
  • Checks passedপাস করা চেক0 / 6
  • Timeসময়0 s
locatorlocatortestটেস্টSaveSavebuttonবাটনmatch 1 of 2মিল ১ / ২SaveSavebuttonবাটনmatch 2 of 2মিল ২ / ২one elementএকটা element·visibleদৃশ্যমান·stableস্থির·not coveredঢাকা নয়·enabledচালু (enabled)·not inertinert নয়·

You’ll learnআপনি শিখবেন

  • Why a locator must match one elementকেন locator-এ একটাই element মিলতে হবে
  • Which six checks a click waits forclick কোন ছয়টা চেকের জন্য অপেক্ষা করে
  • What fires the clickকখন click হয়
  • How an assertion retries for 5 secondsassertion কীভাবে ৫ সেকেন্ড আবার চেষ্টা করে

What it is

Playwright Test is an end-to-end test framework for web apps. It bundles a test runner, assertions, isolation, parallel runs, and tools Source 1সোর্স 1. It runs tests on Chromium, WebKit, and Firefox, on Windows, Linux, and macOS. It runs locally or in CI, headless or headed Source 1সোর্স 1.

A test does two things: it performs actions, and it checks the state against expectations Source 2সোর্স 2. Playwright waits for the actionability checks to pass before each action, so you do not add manual waits Source 2সোর্স 2.

Each test runs in its own browser context: a clean, incognito-like profile Source 10সোর্স 10. It has its own local storage, session storage, and cookies Source 10সোর্স 10. So the pages of two tests are isolated from each other Source 2সোর্স 2.

This page covers the test runner itself. For Playwright with Claude Code, see Browser Testing with Playwright.

সহজ English

Playwright Test is a tool that tests a web app from end to end. It comes with what a test needs: a test runner, checks, separate test runs, many tests at once, and tools Source 1সোর্স 1. It works with the Chromium, WebKit, and Firefox browsers, on Windows, Linux, and macOS. It works on your computer or in CI, with the browser window shown or hidden Source 1সোর্স 1.

A test does something on the page, then checks the result Source 2সোর্স 2. Playwright waits for each element before it acts, so you do not add waits Source 2সোর্স 2.

Each test gets a clean browser profile, like a private window Source 10সোর্স 10. It has its own storage and cookies Source 10সোর্স 10. So two tests never share a page Source 2সোর্স 2.

This page is about the test runner. For Playwright with Claude Code, see Browser Testing with Playwright.

বাংলা ব্যাখ্যা

Playwright Test হলো web app-এর end-to-end টেস্টের একটা framework। এর ভেতরেই আছে test runner, assertion, isolation, একসাথে অনেক টেস্ট চালানো আর দরকারি টুল Source 1সোর্স 1। এটা Chromium, WebKit আর Firefox-এ চলে, Windows, Linux আর macOS-এ। নিজের কম্পিউটারে বা CI-তে, browser দেখিয়ে (headed) বা না দেখিয়ে (headless), দুইভাবেই চালানো যায় Source 1সোর্স 1।

একটা টেস্ট দুটো কাজ করে: পেজে action করে, তারপর অবস্থাটা প্রত্যাশার সাথে মিলিয়ে দেখে Source 2সোর্স 2। প্রতিটা action-এর আগে Playwright নিজেই অপেক্ষা করে, তাই আপনাকে হাতে wait লিখতে হয় না Source 2সোর্স 2।

প্রতিটা টেস্ট নিজের আলাদা browser context-এ চলে: incognito-র মতো একটা পরিষ্কার profile Source 10সোর্স 10। এর local storage, session storage আর cookie আলাদা Source 10সোর্স 10। তাই দুটো টেস্টের পেজ একে অপরের থেকে আলাদা থাকে Source 2সোর্স 2।

এই পেজে শুধু test runner-এর কথা। Claude Code-এর সাথে Playwright-এর জন্য Browser Testing with Playwright পেজটা দেখুন।

How it works

Four ideas carry most tests.

page.getByRole('button', { name: 'Save' })   a locator: how to find the button
        │
        ▼
await locator.click()                    waits: one element, visible, stable,
        │                                not covered, enabled, not inert
        ▼
await expect(message).toBeVisible()      retries until true, or fails after 5 s

সহজ English

Four ideas do most of the work.

বাংলা ব্যাখ্যা

বেশিরভাগ টেস্ট চারটা ধারণার ওপর চলে।

  • Locator element খুঁজে দেয়। Locator হলো পেজে যেকোনো মুহূর্তে element খোঁজার একটা উপায় Source 3সোর্স 3। প্রস্তাবিত built-in locator-এর মধ্যে আছে page.getByRole(), page.getByText(), page.getByLabel(), page.getByPlaceholder() আর page.getByTestId() Source 3সোর্স 3। page.getByTestId() element খোঁজে তার data-testid attribute দিয়ে Source 3সোর্স 3। Playwright আগে ব্যবহারকারী যা দেখেন সেটা দিয়ে খুঁজতে বলে, যেমন role Source 3সোর্স 3।
  • Locator কড়া (strict)। একটা locator একাধিক element পেলে action একটা error দিয়ে থেমে যায় Source 3সোর্স 3।
  • Action অপেক্ষা করে। Click-এর আগে Playwright দেখে যে element ঠিক একটা কি না। Element-কে দৃশ্যমান, স্থির (animation চলছে না), অন্য কিছুর নিচে ঢাকা নয়, enabled আর inert নয় হতে হবে Source 4সোর্স 4। সময়ের মধ্যে এগুলো না মিললে click একটা TimeoutError দিয়ে fail করে Source 4সোর্স 4।
  • Assertion বারবার চেষ্টা করে। await expect(locator).toBeVisible() পাস না করা বা সময় শেষ না হওয়া পর্যন্ত বারবার চেক করে Source 5সোর্স 5। ডিফল্ট সময় ৫ সেকেন্ড Source 5সোর্স 5।

Try it

You need Node.js: the latest 22.x, 24.x, or 26.x Source 1সোর্স 1.

  1. Create a project. Make a new folder, and run npm init playwright@latest in it. The command creates a new project, or adds Playwright to an existing one Source 1সোর্স 1. It asks for TypeScript or JavaScript; the default is TypeScript Source 1সোর্স 1. It creates playwright.config.ts and a first test, tests/example.spec.ts Source 1সোর্স 1. The config holds the browsers, timeouts, retries, projects, and reporters Source 1সোর্স 1.
  2. Run the example. By default, npx playwright test runs the tests headless, in parallel, on Chromium, Firefox, and WebKit Source 1সোর্স 1. Add --headed to see the browser, or --ui to open UI Mode Source 1সোর্স 1. npx playwright show-report opens the HTML report Source 1সোর্স 1.
  3. Record your steps. npx playwright codegen demo.playwright.dev/todomvc opens a browser and the Playwright Inspector Source 7সোর্স 7. Click and type in the demo app, and Playwright writes the code for your actions Source 7সোর্স 7.
  4. Write a test. Save this as tests/todo.spec.ts and run npx playwright test. It uses built-in locators Source 3সোর্স 3 and auto-retrying assertions Source 5সোর্স 5.
import { test, expect } from '@playwright/test';

test('a new todo shows in the list', async ({ page }) => {
  await page.goto('https://demo.playwright.dev/todomvc');
  const newTodo = page.getByPlaceholder('What needs to be done?');
  await newTodo.fill('Buy milk');
  await newTodo.press('Enter');
  await expect(page.getByTestId('todo-title')).toHaveText(['Buy milk']);
  await expect(page.getByText('1 item left')).toBeVisible();
});
  1. Debug it. npx playwright test --debug opens a browser and the Playwright Inspector Source 11সোর্স 11. Its step over button steps through the test Source 11সোর্স 11. UI Mode lets you explore, run, and debug tests, with time travel and a watch mode Source 12সোর্স 12.

সহজ English

You need Node.js: the latest 22.x, 24.x, or 26.x Source 1সোর্স 1.

  1. Make a project. Make a new folder, and run npm init playwright@latest in it Source 1সোর্স 1. It asks for TypeScript or JavaScript; TypeScript is the default Source 1সোর্স 1. You get playwright.config.ts and a first test, tests/example.spec.ts Source 1সোর্স 1.
  2. Run it. By default, npx playwright test runs the tests on three browsers at once, with no window Source 1সোর্স 1. Add --headed to watch, or --ui for UI Mode. npx playwright show-report opens the report Source 1সোর্স 1.
  3. Record your clicks. npx playwright codegen demo.playwright.dev/todomvc opens a browser and the Inspector. Use the demo app, and Playwright writes the code for you Source 7সোর্স 7.
  4. Write a test. Save this as tests/todo.spec.ts and run npx playwright test. It uses built-in locators Source 3সোর্স 3 and auto-retrying assertions Source 5সোর্স 5.
import { test, expect } from '@playwright/test';

test('a new todo shows in the list', async ({ page }) => {
  await page.goto('https://demo.playwright.dev/todomvc');
  const newTodo = page.getByPlaceholder('What needs to be done?');
  await newTodo.fill('Buy milk');
  await newTodo.press('Enter');
  await expect(page.getByTestId('todo-title')).toHaveText(['Buy milk']);
  await expect(page.getByText('1 item left')).toBeVisible();
});
  1. Find a problem. npx playwright test --debug opens the browser and the Inspector. You can go through the test one step at a time Source 11সোর্স 11. UI Mode lets you explore, run, and debug tests, go back in time, and use a watch mode Source 12সোর্স 12.

বাংলা ব্যাখ্যা

আপনার Node.js লাগবে: সর্বশেষ 22.x, 24.x বা 26.x Source 1সোর্স 1।

  1. একটা project বানান। একটা নতুন folder বানিয়ে তাতে npm init playwright@latest চালান Source 1সোর্স 1। এটা জানতে চায় TypeScript না JavaScript; ডিফল্ট হলো TypeScript Source 1সোর্স 1। আপনি পাবেন playwright.config.ts আর প্রথম টেস্ট tests/example.spec.ts Source 1সোর্স 1।
  2. চালিয়ে দেখুন। ডিফল্টভাবে npx playwright test তিনটা browser-এ একসাথে, window ছাড়া (headless) টেস্ট চালায় Source 1সোর্স 1। দেখতে চাইলে --headed যোগ করুন, আর UI Mode-এর জন্য --ui। রিপোর্ট খুলতে npx playwright show-report Source 1সোর্স 1।
  3. আপনার ক্লিক রেকর্ড করুন। npx playwright codegen demo.playwright.dev/todomvc একটা browser আর Playwright Inspector খোলে। Demo app-এ ক্লিক আর টাইপ করুন, Playwright নিজেই কোড লিখে দেবে Source 7সোর্স 7।
  4. একটা টেস্ট লিখুন। নিচের কোডটা tests/todo.spec.ts নামে সেভ করে npx playwright test চালান। এতে আছে built-in locator Source 3সোর্স 3 আর নিজে থেকে retry করা assertion Source 5সোর্স 5।
import { test, expect } from '@playwright/test';

test('a new todo shows in the list', async ({ page }) => {
  await page.goto('https://demo.playwright.dev/todomvc');
  const newTodo = page.getByPlaceholder('What needs to be done?');
  await newTodo.fill('Buy milk');
  await newTodo.press('Enter');
  await expect(page.getByTestId('todo-title')).toHaveText(['Buy milk']);
  await expect(page.getByText('1 item left')).toBeVisible();
});
  1. সমস্যা খুঁজুন। npx playwright test --debug browser আর Inspector খোলে, আর আপনি ধাপে ধাপে টেস্টটা চালাতে পারেন Source 11সোর্স 11। UI Mode দিয়ে টেস্ট ঘুরে দেখা, চালানো আর debug করা যায়, সাথে আছে সময়ে পিছিয়ে দেখা (time travel) আর watch mode Source 12সোর্স 12।

How a tester uses it

// tests/todo-page.ts
import type { Locator, Page } from '@playwright/test';

export class TodoPage {
  readonly page: Page;
  readonly newTodo: Locator;
  readonly titles: Locator;

  constructor(page: Page) {
    this.page = page;
    this.newTodo = page.getByPlaceholder('What needs to be done?');
    this.titles = page.getByTestId('todo-title');
  }

  async goto() {
    await this.page.goto('https://demo.playwright.dev/todomvc');
  }

  async add(text: string) {
    await this.newTodo.fill(text);
    await this.newTodo.press('Enter');
  }
}
// tests/todo-pom.spec.ts
import { test, expect } from '@playwright/test';
import { TodoPage } from './todo-page';

test('two todos keep their order', async ({ page }) => {
  const todos = new TodoPage(page);
  await todos.goto();
  await todos.add('Buy milk');
  await todos.add('Pay bills');
  await expect(todos.titles).toHaveText(['Buy milk', 'Pay bills']);
});

সহজ English

বাংলা ব্যাখ্যা

  • ব্যবহারকারী যা দেখেন, সেটাই টেস্ট করুন। টেস্ট দেখবে app তার ব্যবহারকারীদের জন্য ঠিকমতো কাজ করে কি না; কোড ভেতরে কীভাবে বানানো, সেটার ওপর নির্ভর করবে না Source 9সোর্স 9। XPath বা CSS selector-এর বদলে ব্যবহারকারী যা দেখেন সেটা দিয়ে element খুঁজুন। DOM সহজেই বদলায়, আর তখন DOM-এর গঠনের ওপর নির্ভর করা টেস্ট fail করে Source 9সোর্স 9।
  • Page object ব্যবহার করুন। Playwright-এর উদাহরণে page object হলো একটা পেজের জন্য একটা helper class Source 6সোর্স 6। এটা সেই পেজের জন্য সহজ ধাপ দেয়, আর selector-গুলো এক জায়গায় রাখে Source 6সোর্স 6।
  • Setup ভাগ করে নিন। test.describe টেস্টগুলোকে একটা group-এ রাখে। test.beforeEach আর test.afterEach প্রতিটা টেস্টের আগে আর পরে চলে Source 2সোর্স 2।
  • CI-এর fail বুঝুন। ডিফল্ট config-এ fail করা টেস্ট প্রথমবার আবার চলার সময় trace রেকর্ড হয় (on-first-retry) Source 8সোর্স 8। CI-তে retry ২ বার, আর নিজের কম্পিউটারে ০ বার Source 8সোর্স 8। HTML report থেকে trace খুলুন। নিজের কম্পিউটারে --trace on দিলে trace জোর করে চালু হয় Source 8সোর্স 8।
  • শুধু নিজের জিনিস টেস্ট করুন। যে বাইরের site-এর link বা third-party server আপনার নিয়ন্ত্রণে নেই, সেগুলো টেস্ট করবেন না Source 9সোর্স 9।

Common mistakes

সহজ English

বাংলা ব্যাখ্যা

  • হাতে লেখা assertion। expect(await page.getByText('welcome').isVisible()).toBe(true) অপেক্ষা করে না: একবার দেখে সাথে সাথে ফিরে আসে Source 9সোর্স 9। এর বদলে লিখুন await expect(page.getByText('welcome')).toBeVisible(), যেটা শর্ত পূরণ না হওয়া পর্যন্ত অপেক্ষা করে Source 9সোর্স 9।
  • await বাদ পড়া। যে assertion বারবার চেষ্টা করে, সেগুলো async, তাই এগুলোর আগে await দিতেই হবে Source 5সোর্স 5।
  • টেস্টে sleep রাখা। Playwright নিজেই action-এর আগে অপেক্ষা করে, তাই হাতে wait লাগে না Source 2সোর্স 2।
  • CSS class বা XPath দিয়ে element খোঁজা। এগুলো টেস্টকে DOM-এর গঠনের সাথে বেঁধে দেয়, আর DOM সহজেই বদলায় Source 9সোর্স 9। এর বদলে ব্যবহারকারী যা দেখেন সেই locator ব্যবহার করুন Source 3সোর্স 3।
  • একাধিক element-এ মেলা locator। Locator strict, তাই action error দেয় Source 3সোর্স 3। Locator সরু করুন, যেমন locator.filter() দিয়ে Source 3সোর্স 3। locator.first() strictness check এড়িয়ে যায়, আর docs এটা ব্যবহারের পরামর্শ দেয় না Source 3সোর্স 3।
  • একটা টেস্ট আরেকটার ওপর নির্ভর করা। প্রতিটা টেস্ট পুরো আলাদা থাকবে আর নিজে নিজে চলবে Source 9সোর্স 9।

What a tester can check

Tutorial advice

This list is the tutorial's own advice, not a fact from a source.

  • Locators. Do the tests find elements by role, label, text, or test id? Count the CSS classes and XPath selectors that are left.
  • Assertions. Does every check of the page start with await expect(? Search for isVisible() inside an expect(.
  • Waits. Search the suite for waitForTimeout. Each one is a sleep that a web-first assertion can replace.
  • Isolation. Run one test alone, then the whole suite. A test that passes alone but fails in the suite, or the other way round, shares state with another test.
  • CI evidence. Does a failed CI run keep the HTML report and the trace as artifacts?
  • Page objects. Does each page object hold only the locators and steps of its own page?
  • Scope. Do the tests stop at your app, or do they also test sites that you do not own?

সহজ English

Tutorial advice

This list is the tutorial's own advice, not a fact from a source.

  • Locators. Do the tests find elements by role, label, text, or test id? Count the CSS classes and XPath that are left.
  • Checks. Does every check start with await expect(? Look for isVisible() inside an expect(.
  • Waits. Look for waitForTimeout. Each one is a sleep that a waiting check can replace.
  • Separate tests. Run one test alone, then all of them. A test that passes alone but fails with the others, or the other way round, shares something with another test.
  • CI proof. Does a failed CI run keep the report and the trace?
  • Page objects. Does each page object hold only its own page?
  • Scope. Do the tests stay on your app, or do they also test sites you do not own?

বাংলা ব্যাখ্যা

Tutorial advice

এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, কোনো source থেকে নেওয়া তথ্য নয়।

  • Locator। টেস্টগুলো কি role, label, text বা test id দিয়ে element খোঁজে? কতগুলো CSS class আর XPath selector রয়ে গেছে, গুনে দেখুন।
  • Assertion। পেজের প্রতিটা চেক কি await expect( দিয়ে শুরু হয়? expect(-এর ভেতরে isVisible() খুঁজুন।
  • Wait। পুরো suite-এ waitForTimeout খুঁজুন। প্রতিটা একটা sleep, যার জায়গায় web-first assertion বসানো যায়।
  • Isolation। একটা টেস্ট একা চালান, তারপর পুরো suite। যে টেস্ট একা পাস করে কিন্তু suite-এ fail করে, বা উল্টোটা, সেটা অন্য কোনো টেস্টের সাথে state ভাগ করছে।
  • CI-এর প্রমাণ। CI-তে fail হলে কি HTML report আর trace artifact হিসেবে থেকে যায়?
  • Page object। প্রতিটা page object কি শুধু নিজের পেজের locator আর ধাপ রাখে?
  • Scope। টেস্টগুলো কি আপনার app-এই থামে, নাকি আপনার নয় এমন site-ও টেস্ট করে?

Key words

TermMeaning
Playwright TestAn end-to-end test framework for web apps, with its own test runner and assertions.
LocatorA way to find elements on the page at any moment, such as page.getByRole().
Strict locatorAn action on a locator throws an error if more than one element matches.
Actionability checksThe checks before an action: one element, visible, stable, not covered, enabled, and not inert.
Web-first assertionAn await expect(...) check that retries until it passes or times out (5 seconds by default).
Browser contextThe clean, incognito-like profile that each test gets, with its own storage and cookies.
Page objectA class that gives one page a higher-level API and keeps its selectors in one place.
CodegenThe test generator: it records your actions in a browser as test code.
TraceRecorded on the first retry of a failed test by the default config; you open it from the trace icon in the HTML report.
UI ModeA mode to explore, run, and debug tests, with time travel and a watch mode.
  1. [1]
    Installation

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  2. [2]
    Writing tests

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  3. [3]
    Locators

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  4. [4]
    Auto-waiting

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  5. [5]
    Assertions

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  6. [6]
    Page object models

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  7. [7]
    Generating tests

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  8. [8]
    Trace viewer

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  9. [9]
    Best Practices

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  10. [10]
    Isolation

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  11. [11]
    Running and debugging tests

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  12. [12]
    UI Mode

    Playwright (Microsoft) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15