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

Part 33পর্ব 33 · Agentic QA

Playwright Automation with Claude

Asking Claude for a Playwright test is easy. Knowing whether the test is right is the hard part. This page teaches Playwright Test itself: the setup, the test structure, browser contexts, locators, assertions, fixtures, and the debug tools. Then it shows how to use Claude to create, explain, debug, and refactor tests, and how to review each generated test before you trust it. If you know the tool, you can see when Claude is wrong.

17 min read17 মিনিটে পড়া যায় · 11 sections11টি সেকশন · 22 sources22টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Each test gets its own browser contextপ্রতিটা test পায় নিজের browser context

Run two tests and see their storage stay apart, then break the isolation.দুটো test চালিয়ে দেখুন তাদের storage আলাদা থাকে, তারপর isolation ভেঙে দেখুন।

2 min2 মিনিট7 steps7টি ধাপ
  • Contextsকনটেক্সট0
  • Cookies seen by BB যত cookie দেখে0
  • Browser launchesbrowser চালু1
launch · 1চালু · 1testerটেস্টারBrowserব্রাউজারsharedভাগ করাone launch for all testsসব test-এ একবার চালুTest Aটেস্ট Acontextকনটেক্সটTest Bটেস্ট Bcontextকনটেক্সট

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

  • Browser, context, page: three layersbrowser, context, page: তিনটা স্তর
  • Each test gets its own contextপ্রতিটা test পায় নিজের context
  • Isolation stops cascading failuresisolation ব্যর্থতার ধাপে ধাপে ছড়ানো আটকায়
  • Fixtures and several contexts in one testfixture, আর এক test-এ একাধিক context

Install and configure Playwright Test

Install. One command starts a new project or adds Playwright to an existing one: Source 1সোর্স 1

npm init playwright@latest

The command asks four questions: Source 1সোর্স 1

  • TypeScript or JavaScript. The default is TypeScript.
  • The tests folder. The default is tests, or e2e if tests already exists.
  • Whether to add a GitHub Actions workflow.
  • Whether to install the Playwright browsers. The default is yes.

You can run it again later. It does not overwrite existing tests. Source 1সোর্স 1

What it creates. Playwright downloads the browser binaries and writes playwright.config.ts, package.json, a lock file, and tests/example.spec.ts. Source 1সোর্স 1

Browsers and system. Playwright supports Chromium, WebKit, and Firefox on Windows, Linux, and macOS. Source 1সোর্স 1 It needs Node.js 22.x, 24.x, or 26.x (the latest of each). Source 1সোর্স 1 By default, tests run headless and in parallel across Chromium, Firefox, and WebKit. Source 1সোর্স 1

Version. The newest entry in the release notes, read on 2026-11-15, is version 1.65. Source 2সোর্স 2 Check your version with npx playwright --version. Update with npm install -D @playwright/test@latest, then npx playwright install --with-deps. Source 1সোর্স 1

Configure. playwright.config.ts holds the target browsers, timeouts, retries, projects, and reporters. Source 1সোর্স 1 These keys are common: Source 3সোর্স 3

KeyExample value from the docs
testDir'tests'
fullyParalleltrue
forbidOnly!!process.env.CI
retriesprocess.env.CI ? 2 : 0
use.baseURL'http://localhost:3000'

সহজ English

One command sets up Playwright: npm init playwright@latest. It works for a new project and for an existing one. Source 1সোর্স 1

It asks you four things: TypeScript or JavaScript, the name of the tests folder, whether to add a GitHub Actions workflow, and whether to install browsers. Source 1সোর্স 1 You can run it again later. It does not overwrite your tests. Source 1সোর্স 1

It downloads the browsers. It also writes a config file, playwright.config.ts, and one example test. Source 1সোর্স 1

Playwright runs Chromium, WebKit, and Firefox. It needs Node.js 22, 24, or 26. Source 1সোর্স 1 Tests run headless by default. Source 1সোর্স 1

The newest version in the release notes on 2026-11-15 is 1.65. Source 2সোর্স 2 Run npx playwright --version to see your version. Source 1সোর্স 1

The config file holds the browsers, timeouts, retries, projects, and reporters. Source 1সোর্স 1

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

একটি command দিয়েই Playwright set up হয়: npm init playwright@latest। এটি নতুন project শুরু করে, অথবা আগের project-এ Playwright যোগ করে। Source 1সোর্স 1

Command-টি চারটি প্রশ্ন করে: TypeScript না JavaScript (default TypeScript), tests folder-এর নাম (default tests, আর tests থাকলে e2e), GitHub Actions workflow যোগ করবেন কি না, আর browser install করবেন কি না (default হ্যাঁ)। Source 1সোর্স 1 পরে আবার চালালেও এটি আপনার আগের test overwrite করে না। Source 1সোর্স 1

এটি browser binary download করে এবং playwright.config.ts, package.json, একটি lock file আর tests/example.spec.ts তৈরি করে। Source 1সোর্স 1

Playwright Windows, Linux ও macOS-এ Chromium, WebKit আর Firefox চালায়। এর জন্য Node.js 22.x, 24.x বা 26.x লাগে। Source 1সোর্স 1 Default-ভাবে test headless আর parallel চলে। Source 1সোর্স 1

2026-11-15 তারিখে release notes-এর সবচেয়ে নতুন version হলো 1.65। Source 2সোর্স 2 নিজের version দেখতে npx playwright --version চালান। Source 1সোর্স 1

playwright.config.ts-এ browser, timeout, retry, project আর reporter এক জায়গায় থাকে। Source 1সোর্স 1 সাধারণ key হলো testDir, fullyParallel, forbidOnly, retries আর use.baseURL। Source 3সোর্স 3

Write and run a test

Structure. A test file imports test and expect from @playwright/test. Source 4সোর্স 4 A test performs actions and asserts the state against expectations. Source 4সোর্স 4

The example below is the tutorial's own. It follows the pattern of the docs:

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

test.describe('login page', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('https://staging.example.com/login');
  });

  test('shows an error for a wrong password', async ({ page }) => {
    await page.getByLabel('Email').fill('qa-user@example.com');
    await page.getByLabel('Password').fill('wrong-password');
    await page.getByRole('button', { name: 'Sign in' }).click();
    await expect(page.getByText('Invalid email or password')).toBeVisible();
  });
});

Run. These commands come from the docs: Source 5সোর্স 5

CommandWhat it does
npx playwright testRuns all tests, headless
npx playwright test --headedShows the browser window
npx playwright test --uiOpens UI mode
npx playwright test --project webkitRuns one project only
npx playwright test login.spec.tsRuns one file
npx playwright test -g "wrong password"Runs the tests with that title
npx playwright test --last-failedRuns only the tests that failed last time
npx playwright show-reportOpens the HTML report

The HTML report opens by itself if some tests failed. Source 5সোর্স 5

Projects. A project is a group of tests with the same configuration. Source 6সোর্স 6 Use one project for each browser, or run the same tests logged in and logged out. Source 6সোর্স 6

সহজ English

A test file imports test and expect from @playwright/test. Source 4সোর্স 4 A test does some actions. Then it checks the result.

You run tests from the terminal. Source 5সোর্স 5

  • npx playwright test runs all tests.
  • --headed shows the browser.
  • --ui opens UI mode.
  • --project webkit runs one project only.
  • -g runs the tests whose title matches.
  • --last-failed runs again only the tests that failed.
  • npx playwright show-report opens the HTML report.

The report opens by itself when a test fails. Source 5সোর্স 5

A project is a group of tests with the same settings. You can have one project for each browser. Source 6সোর্স 6

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

একটি test file @playwright/test থেকে test আর expect import করে। Source 4সোর্স 4 Test কিছু action করে, তারপর ফলাফল assert করে।

Terminal থেকে test চালান: npx playwright test সব test চালায়, --headed browser window দেখায়, --ui UI mode খোলে, --project webkit শুধু একটি project চালায়, -g title দিয়ে test বাছে, আর --last-failed শুধু আগের বার fail করা test আবার চালায়। Source 5সোর্স 5 কোনো test fail করলে HTML report নিজে থেকে খোলে। অন্য সময় npx playwright show-report চালান। Source 5সোর্স 5

Project হলো একই configuration-এর একদল test। প্রতিটি browser-এর জন্য একটি project রাখা যায়, অথবা একই test logged in আর logged out অবস্থায় চালানো যায়। Source 6সোর্স 6

Browser, context, page, and fixtures

Three layers. Playwright can create multiple browser contexts in one scenario, and a page belongs to a context. Source 7সোর্স 7

Fixtures. A fixture sets up the environment for a test: everything it needs and nothing else. Fixtures are isolated between tests. Source 8সোর্স 8

Built-in fixtureWhat it gives
pageAn isolated page for this test Source 8সোর্স 8
contextThe isolated context that the page belongs to Source 8সোর্স 8
browserThe browser, shared across tests to save resources Source 8সোর্স 8
browserNamechromium, firefox, or webkit Source 8সোর্স 8
requestAn isolated APIRequestContext for API calls Source 8সোর্স 8

Custom fixtures. test.extend() creates a new test object with your own fixture. Source 8সোর্স 8 The code before await use() is the setup. The code after it is the teardown. Source 8সোর্স 8 Playwright sets up only the fixtures that a test uses. Source 8সোর্স 8

The example below is the tutorial's own. It gives each test a loginPage page object:

import { test as base } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';

export const test = base.extend<{ loginPage: LoginPage }>({
  loginPage: async ({ page }, use) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await use(loginPage);
  },
});
export { expect } from '@playwright/test';

A test then asks for it by name: test('...', async ({ loginPage }) => { ... }).

সহজ English

Think of three layers. A browser can run several browser contexts. A context is like an incognito profile. A page belongs to a context. Source 7সোর্স 7

Playwright makes a new context for each test. Source 7সোর্স 7 So each test has its own cookies and storage. A test that fails does not leave a mess for the next test. One test can also open two contexts, for example an admin and a user who chat. Source 7সোর্স 7

A fixture is something that a test needs, ready before the test starts. Source 8সোর্স 8 page is a fixture. Others are context, browser, browserName, and request. Source 8সোর্স 8

You can make your own fixture with test.extend(). Source 8সোর্স 8 The code before await use() prepares it. The code after await use() cleans up. Source 8সোর্স 8 Playwright prepares only the fixtures that a test asks for. Source 8সোর্স 8

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

তিনটি স্তর মনে রাখুন: browser, browser context আর page। Browser context একটি incognito profile-এর মতো। একই browser-এর ভেতরেও প্রতিটি context পুরোপুরি আলাদা। Source 7সোর্স 7

Playwright প্রতিটি test-এর জন্য একটি নতুন context আর তার ভেতরে একটি default page তৈরি করে। Source 7সোর্স 7 তাই প্রতিটি test-এর নিজের local storage, session storage আর cookie থাকে। একটি test-এ একাধিক context-ও বানানো যায়, যেমন chat flow-তে একজন admin আর একজন user। Source 7সোর্স 7

Fixture হলো test-এর environment: test-এর যা দরকার ঠিক ততটুকু। Fixture এক test থেকে আরেক test-এ আলাদা থাকে। Source 8সোর্স 8 Built-in fixture হলো page, context, browser (সব test-এ shared), browserName আর request। Source 8সোর্স 8

নিজের fixture বানাতে test.extend() ব্যবহার করুন। Source 8সোর্স 8 await use()-এর আগের code হলো setup, পরের code হলো teardown। Source 8সোর্স 8 যে fixture কোনো test চায়, Playwright শুধু সেটিই set up করে। Source 8সোর্স 8 Technical panel-এর loginPage fixture-টি tutorial-এর নিজের উদাহরণ।

Locators that survive change

A locator is a way to find an element on the page at any moment. Each time an action uses it, Playwright finds an up-to-date element. Source 9সোর্স 9

The recommended built-in locators, in the order that the docs list them: Source 9সোর্স 9

LocatorFinds an element by
getByRole()Its accessibility role and name, for example a button named "Sign in"
getByText()Its text content
getByLabel()The text of the label of a form control
getByPlaceholder()The placeholder of an input
getByAltText()The text alternative of an image
getByTitle()Its title attribute
getByTestId()Its data-testid attribute (you can configure another one)

Priority. The docs recommend role locators first, because they are closest to how users and assistive technology see the page. Source 9সোর্স 9 Use text locators for non-interactive elements such as div and span. Source 9সোর্স 9 Test ids are the most resilient, but they are not user facing. Source 9সোর্স 9 To use another attribute, set testIdAttribute in use of the config. Source 9সোর্স 9

Chaining and filtering. Chain locators to narrow the search to one part of the page. Source 10সোর্স 10

await page
  .getByRole('listitem')
  .filter({ hasText: 'Product 2' })
  .getByRole('button', { name: 'Add to cart' })
  .click();

Strictness. Locators are strict. An action throws an error if more than one element matches. Source 9সোর্স 9 first(), last(), and nth() turn this off, but the docs do not recommend them: when the page changes, Playwright can click an element that you did not intend. Source 9সোর্স 9

Why CSS and XPath break. Selectors tied to the DOM structure break when the DOM changes. Source 9সোর্স 9 A selector on CSS classes breaks when a designer changes a class. Source 10সোর্স 10 The docs do not recommend CSS or XPath. Source 9সোর্স 9

// Brittle: tied to the DOM
await page.locator('#tsf > div:nth-child(2) > div.A8SBwf > input').click();
// Resilient: what the user sees
await page.getByRole('button', { name: 'submit' }).click();

Codegen also picks locators in this order: role, text, then test id. Source 11সোর্স 11

সহজ English

A locator tells Playwright how to find an element, such as a button or a text box. Playwright looks for the element again each time it acts. Source 9সোর্স 9

The docs list these built-in locators, and they recommend getByRole() first: Source 9সোর্স 9

  • getByRole() finds an element by what it is and its name, like "the button named Sign in". The docs recommend it first, because users see the page this way.
  • getByText() finds an element by its text. Use it for text that you do not click.
  • getByLabel() finds a form field by its label.
  • getByTestId() finds an element by its test id. It is very stable, but users do not see it.

You can chain locators. For example, first find a list item, then the button inside it. Source 10সোর্স 10

Locators are strict. If two elements match, the action fails with an error. Source 9সোর্স 9 The docs do not recommend nth() for this. The page can change, and then Playwright can click the wrong element. Source 9সোর্স 9

Long CSS or XPath paths follow the structure of the HTML. They break when the HTML changes. Source 9সোর্স 9

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

Locator হলো page-এ কোনো element খোঁজার উপায়। প্রতিটি action-এর সময় Playwright element-টি নতুন করে খোঁজে। Source 9সোর্স 9

Docs যে built-in locator-গুলো recommend করে: getByRole(), getByText(), getByLabel(), getByPlaceholder(), getByAltText(), getByTitle() আর getByTestId()। Source 9সোর্স 9 সবার আগে role locator ব্যবহার করুন, কারণ user আর assistive technology page-কে এভাবেই দেখে। Source 9সোর্স 9 div বা span-এর মতো non-interactive element-এর জন্য text locator ব্যবহার করুন। Source 9সোর্স 9 Test id সবচেয়ে টেকসই, কিন্তু user এটি দেখে না। Source 9সোর্স 9

Locator chain করে page-এর একটি অংশে খোঁজা সীমিত করা যায়, আর filter({ hasText }) দিয়ে বাছাই করা যায়। Source 10সোর্স 10

Locator strict: একাধিক element মিললে action error দেয়। Source 9সোর্স 9 first(), last() বা nth() দিয়ে এটি এড়ানো যায়, কিন্তু docs এগুলো recommend করে না, কারণ page বদলালে Playwright ভুল element-এ click করতে পারে। Source 9সোর্স 9

DOM structure-এর সাথে বাঁধা CSS বা XPath, DOM বদলালেই ভেঙে যায়। Source 9সোর্স 9 Designer একটি CSS class বদলালেও test ভাঙে। Source 10সোর্স 10 Codegen-ও role, text আর test id-কে আগে রাখে। Source 11সোর্স 11

Assertions and auto-waiting

Auto-waiting before actions. Before an action, Playwright runs actionability checks and waits until they pass. If they do not pass within the timeout, the action fails with a TimeoutError. Source 12সোর্স 12 For click(), the element must: Source 12সোর্স 12

  • resolve to exactly one element,
  • be visible and stable (not animating),
  • receive events (no overlay on top of it),
  • be enabled and not inert.

The force option turns off the non-essential checks. Source 12সোর্স 12 So you do not need manual waits. Source 4সোর্স 4

Web-first assertions. An auto-retrying assertion checks the page again and again until the condition is true or the assertion timeout ends. Source 13সোর্স 13 These assertions are async, so you must await them. Source 13সোর্স 13

KindExamplesWaits?
Auto-retryingtoBeVisible(), toHaveText(), toHaveURL(), toHaveCount(), toHaveValue()Yes Source 13সোর্স 13
Non-retryingtoBe(), toEqual(), toBeTruthy(), toContain()No. They can make a test flaky. Source 13সোর্স 13

For a complex check that must retry, use expect.poll or expect.toPass. Source 13সোর্স 13 A soft assertion (expect.soft) does not stop the test, but it marks the test as failed. Source 13সোর্স 13

The wrong way and the right way: Source 10সোর্স 10

// Does not wait: checks once and returns
expect(await page.getByText('welcome').isVisible()).toBe(true);
// Waits and retries until the text is visible
await expect(page.getByText('welcome')).toBeVisible();

Timeouts. The defaults are 5 seconds for each assertion Source 13সোর্স 13 and 30 seconds for each test. Source 14সোর্স 14

The tutorial's advice

Treat a fixed sleep, such as page.waitForTimeout(3000), as a smell in a generated test. It makes the test slow when the app is fast and flaky when the app is slow. Wait for the state that the user sees with a web-first assertion instead. If a test needs more time, find out why before you raise a timeout.

সহজ English

Before Playwright clicks, it waits. It checks that the element is there, visible, still, not covered, and enabled. Source 12সোর্স 12 If this takes too long, the action fails with a timeout error. Source 12সোর্স 12 So you do not need to add your own waits. Source 4সোর্স 4

An assertion is a check, like "the welcome text is visible". Web-first assertions try again and again until the check is true or time runs out. Source 13সোর্স 13 Always put await before them. Source 13সোর্স 13

Some checks do not wait, like toBe() and toEqual(). They check one time only. This can make a test flaky. Source 13সোর্স 13

Do not write expect(await page.getByText('welcome').isVisible()).toBe(true). It does not wait. Write await expect(page.getByText('welcome')).toBeVisible(). Source 10সোর্স 10

An assertion waits 5 seconds by default. Source 13সোর্স 13 A test times out after 30 seconds by default. Source 14সোর্স 14

The tutorial's advice: a fixed sleep in a test is a warning sign. Wait for what the user sees instead.

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

কোনো action-এর আগে Playwright actionability check চালায় এবং সেগুলো pass করা পর্যন্ত অপেক্ষা করে। সময়ের মধ্যে pass না করলে action TimeoutError দিয়ে fail করে। Source 12সোর্স 12 click()-এর জন্য element-কে ঠিক একটি হতে হবে, visible, stable, enabled আর not inert হতে হবে, এবং event গ্রহণ করতে হবে। Source 12সোর্স 12 তাই নিজে থেকে manual wait যোগ করার দরকার নেই। Source 4সোর্স 4

Web-first assertion শর্তটি সত্য না হওয়া বা timeout শেষ না হওয়া পর্যন্ত বারবার check করে। এগুলো async, তাই অবশ্যই await দিন। Source 13সোর্স 13 toBe(), toEqual()-এর মতো non-retrying assertion অপেক্ষা করে না, তাই test flaky হতে পারে। Source 13সোর্স 13

ভুল উপায়: expect(await page.getByText('welcome').isVisible()).toBe(true), কারণ এটি একবার দেখেই ফেরত আসে। সঠিক উপায়: await expect(page.getByText('welcome')).toBeVisible()। Source 10সোর্স 10

Default timeout হলো প্রতিটি assertion-এর জন্য 5 সেকেন্ড Source 13সোর্স 13 আর প্রতিটি test-এর জন্য 30 সেকেন্ড। Source 14সোর্স 14

Tutorial-এর পরামর্শ: generated test-এ page.waitForTimeout(3000)-এর মতো fixed sleep দেখলে সন্দেহ করুন। এর বদলে user যা দেখে, সেই অবস্থার জন্য web-first assertion দিয়ে অপেক্ষা করুন।

Debug a failing test

This section covers four debug tools: UI mode, the trace viewer, the Inspector, and codegen. Learn them before you ask Claude to fix a test, so you can check its fix.

UI mode (npx playwright test --ui). You explore, run, and debug tests with time travel and a watch mode. Source 15সোর্স 15 The pick locator button shows the locator for each element of the DOM snapshot. Source 15সোর্স 15

Trace viewer. A trace records each action of a test. Source 16সোর্স 16

Command or settingWhat it does
npx playwright test --trace onRecords a trace for each test, during development Source 16সোর্স 16
trace: 'on-first-retry'Records a trace only on the first retry, for CI Source 16সোর্স 16
trace: 'retain-on-failure'Records each test, but keeps only the traces of failed tests Source 16সোর্স 16
npx playwright show-trace path/to/trace.zipOpens a saved trace Source 16সোর্স 16

trace: 'on' for every test is not recommended, because it is performance heavy. Source 16সোর্স 16 In the Actions tab, you see the locator and the duration of each action, with Before and After snapshots. Source 16সোর্স 16 The trace viewer loads the trace in your browser and sends no data out. Source 16সোর্স 16

Inspector (--debug). It opens the Playwright Inspector and a headed browser, with the default timeout set to 0. Source 17সোর্স 17 To debug one test, give the file and the line: npx playwright test example.spec.ts:10 --debug. Source 5সোর্স 5 Add page.pause() to stop at one point. Source 17সোর্স 17

Codegen (npx playwright codegen <url>). It records your actions as test code. Source 11সোর্স 11 From the toolbar, you can add three assertions: visibility, text, and value. Source 11সোর্স 11 --save-storage saves cookies, localStorage, and IndexedDB data at the end of the session. Source 11সোর্স 11

The tutorial's advice

Codegen code is a first draft. It records what you clicked, and it adds only the assertions that you choose. Add the checks that matter for the requirement before you keep the test.

সহজ English

Playwright gives you four tools to find out why a test fails.

The tutorial's advice: codegen gives you a first draft. Add the real checks yourself.

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

Test কেন fail করছে, তা খুঁজতে Playwright-এর চারটি tool আছে। Claude-কে test ঠিক করতে বলার আগে এগুলো শিখুন, যাতে তার fix যাচাই করতে পারেন।

  • UI mode (--ui): time travel আর watch mode দিয়ে test explore, run ও debug করা যায়। Source 15সোর্স 15 Pick locator button দিয়ে DOM snapshot-এর element-এর locator দেখা যায়। Source 15সোর্স 15
  • Trace viewer: development-এ --trace on দিন। CI-তে trace: 'on-first-retry' ব্যবহার করুন, এটি শুধু প্রথম retry-তে trace রাখে। trace: 'retain-on-failure' শুধু fail করা test-এর trace রাখে। প্রতিটি test-এ trace চালু রাখা performance-এর জন্য ভারী। Source 16সোর্স 16 npx playwright show-trace দিয়ে trace খুলুন। Actions tab-এ প্রতিটি action-এর locator, সময় আর Before ও After snapshot দেখা যায়। Source 16সোর্স 16
  • Inspector: --debug দিলে headed browser আর Inspector খোলে, default timeout হয় 0। Source 17সোর্স 17 একটি নির্দিষ্ট জায়গায় থামতে page.pause() দিন। Source 17সোর্স 17
  • Codegen: npx playwright codegen <url> আপনার action-কে test code হিসেবে record করে। Toolbar থেকে visibility, text আর value assertion যোগ করা যায়। Source 11সোর্স 11

Tutorial-এর পরামর্শ: codegen-এর code প্রথম খসড়া মাত্র। Requirement-এর জন্য দরকারি check নিজে যোগ করুন।

Use Claude to create, explain, and refactor tests

The tutorial's view: getting a draft from Claude is the easy part. Your job is to make Claude prove that the test is right.

Give Claude the live page. The tutorial's advice: a live page gives Claude the real roles and names to use, so do not let it guess locators from the source code alone. Two tools let it read the running app:

Ask for evidence. Ask Claude for the command that it ran and its output. A claim that "all tests pass" alone tells you very little. Source 20সোর্স 20 Put the check in the prompt, for example "run the tests after, and keep going until they pass". Source 20সোর্স 20

Get a second reviewer. /code-review reviews the diff in a fresh subagent that never saw your conversation. Source 20সোর্স 20 A reviewer that you ask to find problems will always find some, so ask it to skip style. Source 20সোর্স 20

Example prompts. These prompts are the tutorial's own:

Explain this spec line by line. For each locator, say why you chose it
and what happens if two elements match. For each assertion, say what
change in the app would make it fail.
Refactor tests/login.spec.ts into a LoginPage page object and a
loginPage fixture. Do not change any assertion. Run the tests before
and after, and show me both outputs and the git diff.

The Test Agents. Playwright also ships three agents, planner, generator, and healer, which you set up with npx playwright init-agents --loop=claude. Source 21সোর্স 21 The Browser Testing with Playwright page covers them and Playwright MCP in depth.

সহজ English

The tutorial's view: getting a draft from Claude is the easy part. Your job is to make Claude show that the test is right.

The tutorial's advice: let Claude see the real page, not only the code, so it does not guess locators.

Ask Claude for proof: the command that it ran and the output. "All tests pass" alone tells you very little. Source 20সোর্স 20

/code-review checks the change with a fresh helper that did not see your chat. Source 20সোর্স 20 A reviewer that you ask to find problems will always find some, so tell it to skip style. Source 20সোর্স 20

Ask Claude to explain each line, and to say what would make each check fail. When it refactors, tell it not to change any check.

Playwright also has three test agents: planner, generator, and healer. Source 21সোর্স 21 The Browser Testing with Playwright page explains them.

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

Tutorial-এর মত: Claude-এর কাছ থেকে draft পাওয়া সহজ অংশ। আপনার কাজ হলো Claude-কে দিয়ে প্রমাণ করানো যে test-টি সঠিক।

Tutorial-এর পরামর্শ: চলমান page Claude-কে আসল role আর name দেয়, তাই শুধু source code থেকে locator অনুমান করতে না দিয়ে চলমান app দেখার সুযোগ দিন:

  • Playwright MCP: claude mcp add playwright npx @playwright/mcp@latest দিয়ে যোগ করুন। এর জন্য Node.js 20 বা নতুন version লাগে। Source 18সোর্স 18 এটি structured accessibility snapshot-এ কাজ করে, যেখানে প্রতিটি element-এর role আর text থাকে। Source 18সোর্স 18
  • Playwright CLI: npm install -g @playwright/cli@latest আর তারপর playwright-cli install --skills চালান। Source 19সোর্স 19 playwright-cli generate-locator <ref> একটি element-এর locator দেয়। README বলে, CLI call-এ MCP-র চেয়ে কম token লাগে। Source 19সোর্স 19

Claude-এর কাছে প্রমাণ চান: কোন command চালিয়েছে আর তার output। শুধু "সব test pass করেছে" কথাটি প্রায় কিছুই বলে না। Source 20সোর্স 20 /code-review একটি নতুন subagent-এ diff review করে, যে আপনার conversation দেখেনি। Source 20সোর্স 20 Reviewer-কে সমস্যা খুঁজতে বললে সে সবসময় কিছু না কিছু পাবে, তাই style বাদ দিতে বলুন। Source 20সোর্স 20

Tutorial-এর নিজের prompt-এ Claude-কে প্রতিটি line ব্যাখ্যা করতে বলুন, আর refactor করার সময় কোনো assertion না বদলাতে বলুন।

Playwright-এর planner, generator আর healer নামে তিনটি agent-ও আছে, যা npx playwright init-agents --loop=claude দিয়ে set up হয়। Source 21সোর্স 21 বিস্তারিত Browser Testing with Playwright পেজে আছে।

Review a generated test

The tutorial's checklist

Use this checklist on every test that Claude writes or changes. Each row names the Playwright behavior that it protects.

CheckWhy it matters
Each test has at least one assertion on what the user sees.A test with no assertion passes when the feature is broken.
Each web-first assertion has await before expect.Retrying assertions are async and must be awaited. Source 13সোর্স 13 A lint rule, @typescript-eslint/no-floating-promises, finds a missing await. Source 10সোর্স 10
No isVisible() inside a plain expect.That pattern checks once and does not wait. Source 10সোর্স 10
No fixed sleep such as waitForTimeout.Playwright already waits before actions and in web-first assertions. Source 4সোর্স 4
Locators use role, label, text, or test id. No long CSS or XPath chain.DOM-tied selectors break when the DOM changes. Source 9সোর্স 9
No nth(), first(), or last() without a reason in a comment.They can click an element that you did not intend. Source 9সোর্স 9
No force: true without a reason.It turns off non-essential actionability checks. Source 12সোর্স 12
The test does not depend on another test or on run order.Each test gets its own context. Source 7সোর্স 7
No password, token, or real user data in the code.Use environment variables and test accounts.
The assertion can fail.Break the expected value on purpose and watch the test fail.
Claude showed the command and its output.A claim of success alone tells you very little. Source 20সোর্স 20

Read the diff yourself before you merge. If a change to a test makes an expected value weaker, ask why, and check the requirement.

সহজ English

The tutorial gives this checklist for every test that Claude writes or changes:

Read the diff yourself before you merge.

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

Claude যে test লেখে বা বদলায়, তার প্রতিটিতে tutorial-এর এই checklist ব্যবহার করুন:

  • প্রতিটি test-এ user যা দেখে তার ওপর অন্তত একটি assertion আছে। Assertion না থাকলে feature ভাঙা থাকলেও test pass করে।
  • প্রতিটি web-first assertion-এর আগে await আছে। Source 13সোর্স 13 @typescript-eslint/no-floating-promises lint rule বাদ পড়া await ধরে। Source 10সোর্স 10
  • সাধারণ expect-এর ভেতরে isVisible() নেই, কারণ এটি অপেক্ষা করে না। Source 10সোর্স 10
  • waitForTimeout-এর মতো fixed sleep নেই। Playwright নিজেই অপেক্ষা করে। Source 4সোর্স 4
  • Locator হলো role, label, text বা test id। লম্বা CSS বা XPath নেই। Source 9সোর্স 9
  • কারণ ছাড়া nth(), first() বা last() নেই। Source 9সোর্স 9
  • কারণ ছাড়া force: true নেই, কারণ এটি non-essential actionability check বন্ধ করে। Source 12সোর্স 12
  • Test অন্য কোনো test বা চালানোর ক্রমের ওপর নির্ভর করে না। Source 7সোর্স 7
  • Code-এ কোনো password, token বা আসল user data নেই।
  • Assertion fail করতে পারে: ইচ্ছা করে ভুল value দিয়ে দেখুন।
  • Claude command আর তার output দেখিয়েছে। Source 20সোর্স 20

Merge করার আগে diff নিজে পড়ুন।

Practice

The tutorial's exercise

This exercise is the tutorial's own. It uses the web app of the dMoney practice repo, which the Codebase Tour describes. Run it only on your local copy, with a test account.

Where these facts come from

The facts about dMoney come from the files of the public repository at commit 51db34a. They have no cites, because a cite links to an official source. Facts about Playwright and Claude Code link to the official docs.

What dMoney has. The Playwright project is in dmoney-web-react/. Its config uses testDir: './e2e', keeps traces with trace: 'retain-on-failure', and has a setup project and a test project for each of the admin and agent roles (admin depends on admin-setup). Its webServer starts the web app and the API, or reuses running servers. e2e/pages/LoginPage.ts finds the fields with getByLabel and the button with getByRole. An admin login has no OTP step and lands on /profile. The admin credentials come from ADMIN_EMAIL and ADMIN_PASSWORD. The repo asks for @playwright/test ^1.63.0.

  1. Explore. Start Claude Code in dmoney-web-react/, with Playwright MCP added. Source 18সোর্স 18 Type:

    Open http://localhost:3000/login with Playwright MCP. List each field
    and button with its role and accessible name. Do not submit the form.
  2. Write. Type:

    Write e2e/tests/admin/admin-login.spec.ts. Start logged out with
    test.use({ storageState: { cookies: [], origins: [] } }). Use LoginPage.
    Read the credentials from ADMIN_EMAIL and ADMIN_PASSWORD. Assert that
    the URL ends with /profile. Use no fixed waits. Run it with
    npx playwright test e2e/tests/admin/admin-login.spec.ts --project=admin
    and show me the output.

    test.use({ storageState: { cookies: [], origins: [] } }) resets the storage state, so the test is not signed in. Source 22সোর্স 22 The tutorial expects one passing test in the output.

  3. Explain. Ask Claude to explain the spec line by line. Check each answer against the sections above.

  4. Review. Go through the checklist of the section "Review a generated test". Fix each failed row.

  5. Break it. Change the expected URL to /dashboard and run the test again. It must fail after the assertion timeout of 5 seconds, unless the call sets its own timeout. Source 13সোর্স 13

  6. Debug. Open the HTML report with npx playwright show-report, then the trace of the failed test. Source 5সোর্স 5 In the Actions tab, find the failed assertion and look at the Before and After snapshots. Source 16সোর্স 16

  7. Restore. Put /profile back, run the test again, and read git diff. Only the new spec should be in it.

সহজ English

This exercise is the tutorial's own. Use your local copy of the dMoney practice app and a test account. The Codebase Tour page describes the app.

The dMoney facts come from the public repo at commit 51db34a. Its Playwright project is in dmoney-web-react/. It keeps a trace when a test fails. The admin login has no OTP step and ends on /profile. The admin login details come from the variables ADMIN_EMAIL and ADMIN_PASSWORD.

  1. Add Playwright MCP to Claude Code. Source 18সোর্স 18 Ask Claude to open the login page and list each field and button. Tell it not to submit the form.
  2. Ask Claude to write e2e/tests/admin/admin-login.spec.ts. The test starts logged out, uses LoginPage, reads the login details from the variables, and checks that the address ends with /profile. Ask it to run the test and show the output.
  3. Ask Claude to explain each line.
  4. Go through the review checklist.
  5. Change /profile to /dashboard. Run again. The test must fail. An assertion waits 5 seconds by default before it fails. Source 13সোর্স 13
  6. Open the report with npx playwright show-report, then the trace. Source 5সোর্স 5 Look at the failed step and its Before and After pictures. Source 16সোর্স 16
  7. Put /profile back. Run again, and read git diff.

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

এই exercise tutorial-এর নিজের। dMoney practice app-এর local copy আর একটি test account ব্যবহার করুন। Codebase Tour পেজে app-টির বর্ণনা আছে।

dMoney-র তথ্য commit 51db34a-এর public repo থেকে নেওয়া। Playwright project আছে dmoney-web-react/-এ। Test fail করলে trace রাখা হয়। Admin login-এ কোনো OTP ধাপ নেই, এটি /profile-এ গিয়ে শেষ হয়। Admin-এর login তথ্য আসে ADMIN_EMAIL আর ADMIN_PASSWORD variable থেকে।

  1. Claude Code-এ Playwright MCP যোগ করুন। Source 18সোর্স 18 Claude-কে login page খুলে প্রতিটি field আর button-এর role ও নাম জানাতে বলুন। Form submit করতে নিষেধ করুন।
  2. Claude-কে e2e/tests/admin/admin-login.spec.ts লিখতে বলুন: logged out অবস্থায় শুরু, LoginPage ব্যবহার, variable থেকে login তথ্য, আর URL /profile-এ শেষ হয় কি না assert। Test চালিয়ে output দেখাতে বলুন।
  3. Claude-কে প্রতিটি line ব্যাখ্যা করতে বলুন।
  4. Review checklist ধরে test-টি যাচাই করুন।
  5. /profile বদলে /dashboard লিখে আবার চালান। Test-টি fail করতেই হবে। Default-ভাবে একটি assertion fail করার আগে 5 সেকেন্ড অপেক্ষা করে। Source 13সোর্স 13
  6. npx playwright show-report দিয়ে report আর তারপর trace খুলুন। Source 5সোর্স 5 Actions tab-এ fail করা assertion আর তার Before ও After snapshot দেখুন। Source 16সোর্স 16
  7. /profile ফিরিয়ে দিন, আবার চালান, আর git diff পড়ুন।

Common mistakes

MistakeFix
You accept a generated test because Claude says it passes.Ask for the command and its output. A claim of success alone tells you very little. Source 20সোর্স 20
The test uses a fixed sleep to "fix" a flaky step.Remove it. Use a web-first assertion on the state that the user sees. Playwright waits before each action. Source 4সোর্স 4
The assertion does not wait or cannot fail: expect(await locator.isVisible()).toBe(true) checks once and does not wait, Source 10সোর্স 10 and a check on a value that the test set itself cannot fail.Use an auto-retrying assertion with await. Source 10সোর্স 10 Then break the expected value on purpose and watch the test fail (the tutorial's advice).
Claude picks a long CSS or XPath selector from the source code.Give Claude the live page with Playwright MCP or the Playwright CLI. Source 18সোর্স 18 Prefer role locators. Source 9সোর্স 9
A strict mode error is "fixed" with nth() or first().Make the locator unique with a filter or a chain. Source 9সোর্স 9
Traces are on for every test in CI.Use on-first-retry or retain-on-failure. on is performance heavy. Source 16সোর্স 16
A refactor quietly changes an expected value.Ask Claude not to change assertions, and read the diff yourself (the tutorial's advice).

সহজ English

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

  • "Pass করেছে" কথায় বিশ্বাস করা। Claude-এর কাছে command আর output চান। Source 20সোর্স 20
  • Flaky ধাপ ঢাকতে fixed sleep। এটি সরিয়ে দিন। User যা দেখে, তার জন্য web-first assertion দিয়ে অপেক্ষা করুন। Playwright প্রতিটি action-এর আগে নিজেই অপেক্ষা করে। Source 4সোর্স 4
  • দুর্বল assertion। expect(await locator.isVisible()).toBe(true) একবার দেখেই ফেরত আসে, অপেক্ষা করে না। আর test নিজে যে value বসিয়েছে, তার check কখনো fail করে না। await সহ auto-retrying assertion ব্যবহার করুন। Source 10সোর্স 10 তারপর ইচ্ছা করে ভুল value দিয়ে fail হতে দেখুন।
  • Source code থেকে লম্বা CSS বা XPath। Playwright MCP দিয়ে Claude-কে চলমান page দেখান। Source 18সোর্স 18 Role locator আগে ব্যবহার করুন। Source 9সোর্স 9
  • Strict mode error nth() দিয়ে "ঠিক" করা। Filter বা chain দিয়ে locator-কে unique করুন। Source 9সোর্স 9
  • CI-তে প্রতিটি test-এ trace on। এটি ভারী। on-first-retry বা retain-on-failure ব্যবহার করুন। Source 16সোর্স 16
  • Refactor-এ চুপচাপ expected value বদলানো। Claude-কে assertion না বদলাতে বলুন এবং diff নিজে পড়ুন।

Key words

TermMeaning
Playwright TestThe Playwright test framework that this page teaches: test, expect, and fixtures.
Browser contextAn isolated, incognito-like profile. Playwright creates one for each test.
FixtureThe environment that a test needs, such as page. You add your own with test.extend().
LocatorA way to find an element on the page at the moment of each action.
Role locatorgetByRole(): finds an element by its accessibility role and name. The docs recommend it first.
StrictnessAn action on a locator throws an error if more than one element matches.
Actionability checksThe checks that Playwright waits for before an action, such as visible, stable, and enabled.
Web-first assertionAn await expect(...) that retries until the condition is true or the timeout ends.
Trace viewerA tool that shows each recorded action of a test, with its locator and snapshots.
UI mode--ui: run, watch, and debug tests with time travel.
Codegennpx playwright codegen: records your actions in the browser as test code.
Playwright MCPA tool that you add to Claude Code with claude mcp add. It reads the page through accessibility snapshots.
  1. [1]
    Installation

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

  2. [2]
    Release notes

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

  3. [3]
    Configuration

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

  4. [4]
    Writing tests

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

  5. [5]
    Running and debugging tests

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

  6. [6]
    Projects

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

  7. [7]
    Isolation

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

  8. [8]
    Fixtures

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

  9. [9]
    Locators

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

  10. [10]
    Best Practices

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

  11. [11]
    Test generator

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

  12. [12]
    Auto-waiting

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

  13. [13]
    Assertions

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

  14. [14]
    Timeouts

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

  15. [15]
    UI Mode

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

  16. [16]
    Trace viewer

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

  17. [17]
    Debugging Tests

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

  18. [18]
    Playwright MCP

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

  19. [19]
    playwright-cli README

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

  20. [20]
    Best practices for Claude Code

    Anthropic (Claude Code docs) · accessed 2026-11-15দেখা হয়েছে: 2026-11-15

  21. [21]
    Agents

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

  22. [22]
    Authentication

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