<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pratham Rathod</title>
    <description>The latest articles on DEV Community by Pratham Rathod (@pratham_rathod_a08657abf5).</description>
    <link>https://dev.to/pratham_rathod_a08657abf5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3816659%2F2f32ce86-0778-4168-a52a-b41bef1699db.png</url>
      <title>DEV Community: Pratham Rathod</title>
      <link>https://dev.to/pratham_rathod_a08657abf5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pratham_rathod_a08657abf5"/>
    <language>en</language>
    <item>
      <title>Mastering Playwright: Run &amp; Debug Tests Like a Pro</title>
      <dc:creator>Pratham Rathod</dc:creator>
      <pubDate>Wed, 08 Jul 2026 18:11:52 +0000</pubDate>
      <link>https://dev.to/pratham_rathod_a08657abf5/mastering-playwright-run-debug-tests-like-a-pro-4636</link>
      <guid>https://dev.to/pratham_rathod_a08657abf5/mastering-playwright-run-debug-tests-like-a-pro-4636</guid>
      <description>&lt;h1&gt;
  
  
  Mastering Playwright: Run &amp;amp; Debug Tests Like a Pro
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;End-to-end testing is a critical component of modern web development, ensuring your applications work as expected from a user's perspective. Playwright stands out as a powerful, reliable tool for crafting robust E2E tests. But writing tests is just one part of the equation; effectively running, debugging, and analyzing them is where the real efficiency gains happen.&lt;/p&gt;

&lt;p&gt;This guide will equip you with the knowledge to master Playwright's command-line interface (CLI) and built-in tools. You'll learn how to execute tests with precision, debug issues swiftly, and interpret results like a seasoned professional, ultimately enhancing your development workflow and the quality of your applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Concepts
&lt;/h2&gt;

&lt;p&gt;Playwright offers a flexible and powerful way to manage your test execution. Understanding its core concepts for running and debugging tests is key to a smooth development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Your Tests
&lt;/h2&gt;

&lt;p&gt;At its heart, Playwright provides a simple command to kick off your tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, this command does a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Parallel Execution&lt;/strong&gt;: Your tests run in parallel, maximizing efficiency.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Headless Mode&lt;/strong&gt;: No browser window opens, and results appear directly in your terminal. This is great for CI/CD environments.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Multi-Browser&lt;/strong&gt;: It runs tests across all browsers configured in your &lt;code&gt;playwright.config&lt;/code&gt; file (typically Chromium, Firefox, and WebKit).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Running in UI Mode (Highly Recommended)
&lt;/h3&gt;

&lt;p&gt;For an unparalleled developer experience, Playwright's UI Mode is a game-changer. It allows you to visually walk through each step of your test, inspect DOM snapshots, view logs, network requests, and use features like the locator picker and watch mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--ui&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running in Headed Mode
&lt;/h3&gt;

&lt;p&gt;Sometimes you want to see the browser in action without the full UI Mode. Use &lt;code&gt;--headed&lt;/code&gt; to open a browser window and visually observe Playwright interacting with your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--headed&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Targeting Specific Browsers
&lt;/h3&gt;

&lt;p&gt;To run tests on one or more specific browsers, use the &lt;code&gt;--project&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--project&lt;/span&gt; webkit
npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--project&lt;/span&gt; chromium &lt;span class="nt"&gt;--project&lt;/span&gt; firefox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running Specific Tests
&lt;/h3&gt;

&lt;p&gt;Playwright provides fine-grained control over which tests to run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Single File&lt;/strong&gt;: &lt;code&gt;npx playwright test landing-page.spec.ts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Multiple Files/Directories&lt;/strong&gt;: &lt;code&gt;npx playwright test tests/todo-page/ tests/landing-page/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;By Keyword in Filename&lt;/strong&gt;: &lt;code&gt;npx playwright test landing login&lt;/code&gt; (runs files with 'landing' or 'login' in their name)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;By Test Title&lt;/strong&gt;: &lt;code&gt;npx playwright test -g "add a todo item"&lt;/code&gt; (runs tests whose title matches the given string)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Last Failed Tests&lt;/strong&gt;: After a run, re-execute only the tests that previously failed.
&lt;code&gt;npx playwright test --last-failed&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Debugging Your Tests
&lt;/h2&gt;

&lt;p&gt;Debugging is an inevitable part of test development. Playwright offers several powerful ways to pinpoint issues:&lt;/p&gt;

&lt;h3&gt;
  
  
  Debugging with UI Mode (Again, Highly Recommended)
&lt;/h3&gt;

&lt;p&gt;As mentioned, UI Mode is fantastic for debugging. You can step through tests, inspect the page, and use the built-in locator picker and playground to refine your selectors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--ui&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Debugging with Playwright Inspector
&lt;/h3&gt;

&lt;p&gt;For stepping through Playwright API calls and seeing detailed debug logs, the Playwright Inspector is invaluable. It opens a separate window that allows you to control test execution step-by-step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--debug&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also debug specific files or even a particular test by line number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nb"&gt;test &lt;/span&gt;example.spec.ts &lt;span class="nt"&gt;--debug&lt;/span&gt;
npx playwright &lt;span class="nb"&gt;test &lt;/span&gt;example.spec.ts:10 &lt;span class="nt"&gt;--debug&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using &lt;code&gt;console.log&lt;/code&gt; and IDE Debuggers
&lt;/h3&gt;

&lt;p&gt;Don't forget the classics! &lt;code&gt;console.log&lt;/code&gt; is always useful for quick checks, and Playwright tests run in Node.js, so you can leverage your IDE's built-in debugger (e.g., VS Code) for breakpoints and variable inspection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Test Reports
&lt;/h2&gt;

&lt;p&gt;After your tests run, Playwright can generate a comprehensive HTML report. This report is crucial for understanding test failures, filtering results, and exploring the full trace of each test step.&lt;/p&gt;

&lt;p&gt;By default, the report opens automatically if tests fail. Otherwise, you can open it manually:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx playwright show-report&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The HTML report allows you to filter by browser, status (passed, failed, skipped), search for specific tests, and dive into detailed traces, complete with video recordings, screenshots, and step-by-step actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Code Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Let&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;s assume you have a simple Playwright test file named `example.spec.ts` in your `tests` directory:

typescript
// tests/example.spec.ts
import { test, expect } from &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;playwright&lt;/span&gt;&lt;span class="sr"&gt;/test'&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/Playwright/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get started link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Get started&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Installation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})).&lt;/span&gt;&lt;span class="nf"&gt;toBeVisible&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, here are some common commands you'll use to run and debug your tests:&lt;/p&gt;

&lt;p&gt;bash&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Run all tests in headless mode (default)
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Run all tests in UI Mode (highly recommended for development)
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test --ui&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Run all tests in headed mode (browser window opens)
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test --headed&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Run tests specifically on the Chromium browser
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test --project chromium&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Run a specific test file
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test tests/example.spec.ts&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Run tests with a specific title (e.g., 'has title')
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;npx playwright test -g "has title"&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Debug a specific test file using Playwright Inspector
&lt;/h1&gt;

&lt;p&gt;npx playwright test tests/example.spec.ts --debug&lt;/p&gt;

&lt;h1&gt;
  
  
  8. Open the HTML test report manually
&lt;/h1&gt;

&lt;p&gt;npx playwright show-report&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Breakdown
&lt;/h2&gt;

&lt;p&gt;Let's break down the practical commands we just saw:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test&lt;/code&gt;: This is your default command. It executes all tests defined in your project, running them in parallel across all configured browsers (Chromium, Firefox, WebKit) in a headless environment. It's perfect for quick checks or CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test --ui&lt;/code&gt;: This command launches Playwright's incredible UI Mode. It opens a browser window alongside a powerful UI where you can step through tests, inspect elements, and get a detailed trace of execution. Essential for an efficient debugging and development workflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test --headed&lt;/code&gt;: If you need to visually observe your tests running but don't require the full debugging capabilities of UI Mode, this command opens a browser window for each test, allowing you to see Playwright's interactions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test --project chromium&lt;/code&gt;: Use the &lt;code&gt;--project&lt;/code&gt; flag to target specific browsers. Here, tests will only run on Chromium, saving time if you're focused on a particular browser's behavior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test tests/example.spec.ts&lt;/code&gt;: To focus on a single test file, simply pass its path as an argument. This is extremely useful when developing or fixing a specific test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test -g "has title"&lt;/code&gt;: The &lt;code&gt;-g&lt;/code&gt; (grep) flag allows you to run tests based on their title. This is ideal for quickly isolating and running a single test or a small group of tests that share a common title pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright test tests/example.spec.ts --debug&lt;/code&gt;: Adding the &lt;code&gt;--debug&lt;/code&gt; flag to your test command activates the Playwright Inspector. This tool provides a step-by-step debugger for your Playwright API calls, complete with logs, making it easier to understand exactly what your test is doing at each stage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npx playwright show-report&lt;/code&gt;: After any test run, this command will open the comprehensive HTML report in your browser. This report aggregates all test results, providing filtering, searching, and detailed traces for each test, including videos and screenshots of failures. It's your go-to for post-run analysis.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices / Common Pitfalls
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start with UI Mode:&lt;/strong&gt; When developing new tests or debugging existing ones, always begin with &lt;code&gt;npx playwright test --ui&lt;/code&gt;. Its visual feedback, locator picker, and step-through capabilities dramatically speed up development.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target Specific Browsers for Speed:&lt;/strong&gt; During development, use &lt;code&gt;npx playwright test --project chromium&lt;/code&gt; (or your primary browser) to get faster feedback cycles instead of running on all configured browsers every time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage &lt;code&gt;-g&lt;/code&gt; for Focused Debugging:&lt;/strong&gt; If you're debugging a single failing test, use &lt;code&gt;npx playwright test -g "Your Test Title"&lt;/code&gt; to run only that specific test. This avoids unnecessary test runs and keeps your focus tight.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-run Failed Tests Efficiently:&lt;/strong&gt; After an initial test run, use &lt;code&gt;npx playwright test --last-failed&lt;/code&gt; to quickly re-execute only the tests that failed. This is a huge time-saver when iterating on fixes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Playwright Inspector for Deep Dives:&lt;/strong&gt; For complex debugging scenarios where you need to understand the exact sequence of Playwright API calls, the &lt;code&gt;--debug&lt;/code&gt; flag with the Playwright Inspector is your best friend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrate with VS Code Extension:&lt;/strong&gt; For an even more seamless experience, install the Playwright VS Code extension. It allows you to run and debug tests directly from the editor sidebar or next to your test definitions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regularly Review HTML Reports:&lt;/strong&gt; Don't just look at terminal output. The HTML report provides invaluable context, including videos, screenshots, and detailed step traces, which are crucial for understanding intermittent failures or complex scenarios.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Arbitrary &lt;code&gt;waitForTimeout&lt;/code&gt;:&lt;/strong&gt; Instead of &lt;code&gt;await page.waitForTimeout(5000)&lt;/code&gt;, use Playwright's built-in auto-waiting mechanisms, assertions like &lt;code&gt;expect(locator).toBeVisible()&lt;/code&gt;, or specific &lt;code&gt;page.waitFor...&lt;/code&gt; methods for more robust and reliable tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Mastering the execution and debugging of your Playwright tests is just as important as writing them well. By leveraging the powerful command-line interface, the intuitive UI Mode, the detailed Playwright Inspector, and comprehensive HTML reports, you can significantly enhance your testing workflow.&lt;/p&gt;

&lt;p&gt;Embrace these tools and techniques to write more reliable tests, debug issues with greater efficiency, and ultimately deliver higher quality web applications. Happy testing!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Playwright Codegen: Generate Tests &amp; Locators Fast</title>
      <dc:creator>Pratham Rathod</dc:creator>
      <pubDate>Thu, 02 Jul 2026 16:53:48 +0000</pubDate>
      <link>https://dev.to/pratham_rathod_a08657abf5/playwright-codegen-generate-tests-locators-fast-50k1</link>
      <guid>https://dev.to/pratham_rathod_a08657abf5/playwright-codegen-generate-tests-locators-fast-50k1</guid>
      <description>&lt;h1&gt;
  
  
  Playwright Codegen: Generate Tests &amp;amp; Locators Fast
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Generate Playwright tests and locators with Codegen. Record user actions, add assertions like visibility and text, and fine-tune locators for robust, reliable end-to-end tests.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Playwright Codegen provides an efficient way to generate tests and locators automatically, accelerating the test creation process. It opens a browser for interaction and an Inspector for recording and managing generated code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Codegen
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Running Codegen
&lt;/h3&gt;

&lt;p&gt;To start the test generator, use the &lt;code&gt;codegen&lt;/code&gt; command followed by the URL of the website you wish to test. The URL is optional and can be entered directly in the browser window if omitted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright codegen https://demo.playwright.dev/todomvc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command launches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A browser window for interactions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Playwright Inspector, which displays the generated code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Recording a Test
&lt;/h2&gt;

&lt;p&gt;Codegen automatically generates Playwright code as you interact with the browser. It analyzes the page to recommend robust locators (prioritizing &lt;code&gt;role&lt;/code&gt;, &lt;code&gt;text&lt;/code&gt;, and &lt;code&gt;test id&lt;/code&gt;), refining them to uniquely identify elements and reduce flakiness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recording Actions
&lt;/h3&gt;

&lt;p&gt;Perform actions in the browser window, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clicking&lt;/strong&gt;: Clicking on buttons, links, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Filling&lt;/strong&gt;: Typing text into input fields.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Navigating&lt;/strong&gt;: Visiting different pages.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Adding Assertions
&lt;/h3&gt;

&lt;p&gt;You can add assertions directly during recording:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click the "Assert" icon in the Playwright Inspector toolbar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click a page element in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the assertion type from the options:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   **Assert Visibility**: `expect(locator).toBeVisible()`

*   **Assert Text**: `expect(locator).toHaveText()`

*   **Assert Value**: `expect(locator).toHaveValue()`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Managing Recording
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stop Recording&lt;/strong&gt;: Press the "Record" button in the Inspector to pause code generation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copy Code&lt;/strong&gt;: Use the "Copy" button to transfer the generated code to your editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clear Code&lt;/strong&gt;: Use the "Clear" button to reset the Inspector and start a new recording.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once finished, close the Playwright Inspector window or terminate the command in your terminal.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example Generated Test
&lt;/h3&gt;

&lt;p&gt;Below is an example of a test generated by interacting with the &lt;code&gt;todomvc&lt;/code&gt; application (e.g., adding an item and marking it complete).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@playwright/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should add a todo item and mark it complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://demo.playwright.dev/todomvc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Add a new todo item&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByPlaceholder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What needs to be done?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;buy some milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByPlaceholder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What needs to be done?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Enter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Assert the new item is visible&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByLabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;buy some milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBeVisible&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Mark the item as complete&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByLabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Toggle Todo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Assert the item is marked complete (e.g., has a line-through style)&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByLabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;buy some milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toHaveClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generating Locators
&lt;/h2&gt;

&lt;p&gt;Codegen can also be used specifically to generate robust locators for existing tests or new elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stop Recording&lt;/strong&gt;: If recording, press the "Record" button to stop. The "Pick Locator" button will appear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Activate Locator Picker&lt;/strong&gt;: Click the "Pick Locator" button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hover and Select&lt;/strong&gt;: Hover over elements in the browser window. Playwright highlights the element and displays its recommended locator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copy Locator&lt;/strong&gt;: Click on the desired element. Its locator code will appear in the "Locator Playground" next to the "Pick Locator" button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Refine Locator&lt;/strong&gt;: You can edit the locator in the "Locator Playground" to fine-tune it. As you type, Playwright highlights matching elements in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copy to Code&lt;/strong&gt;: Use the "Copy" button to copy the refined locator for use in your tests.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4aflmck55vkqvbfrtgjg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4aflmck55vkqvbfrtgjg.png" alt=" " width="800" height="639"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example Generated Locator
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example generated locator for an 'Add' button&lt;/span&gt;
&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Add&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example generated locator for an input field by placeholder&lt;/span&gt;
&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByPlaceholder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Enter your email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Emulation
&lt;/h2&gt;

&lt;p&gt;Codegen supports generating tests under various emulation conditions without additional setup. You can emulate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Specific viewports and devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Color schemes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Geolocation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Language.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Timezone.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can also preserve authenticated states, allowing you to record tests from a logged-in session. For more details on these advanced features, refer to the comprehensive Playwright Test Generator documentation.&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>automation</category>
      <category>testing</category>
    </item>
    <item>
      <title>Playwright E2E Tests: Actions, Assertions, Hooks</title>
      <dc:creator>Pratham Rathod</dc:creator>
      <pubDate>Sun, 28 Jun 2026 15:02:45 +0000</pubDate>
      <link>https://dev.to/pratham_rathod_a08657abf5/playwright-e2e-tests-actions-assertions-hooks-28d1</link>
      <guid>https://dev.to/pratham_rathod_a08657abf5/playwright-e2e-tests-actions-assertions-hooks-28d1</guid>
      <description>&lt;h1&gt;
  
  
  Playwright E2E Tests: Actions, Assertions, Hooks
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn Playwright E2E testing. Write first test, actions, async assertions, test isolation, leverage hooks for reliable web automation!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This guide provides a practical overview of writing tests with Playwright, focusing on core concepts, actions, assertions, and test organization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Playwright tests are designed for simplicity and reliability. They perform actions on web pages and assert expected states. Playwright automatically handles waiting for elements to become actionable and for assertions to eventually pass, eliminating the need for manual waits and reducing test flakiness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started: Your First Test
&lt;/h2&gt;

&lt;p&gt;Playwright tests are typically written in TypeScript or JavaScript. A basic test involves navigating to a URL and performing assertions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tests/example.spec.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@playwright/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Expect a title "to contain" a substring.&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/Playwright/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get started link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Click the "Get started" link using its role and name.&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Get started&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Expects the page to have a heading with the name "Installation".&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Installation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})).&lt;/span&gt;&lt;span class="nf"&gt;toBeVisible&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When using JavaScript in VS Code, add &lt;code&gt;// @ts-check&lt;/code&gt; at the start of each test file to enable automatic type checking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performing Actions
&lt;/h2&gt;

&lt;p&gt;Most tests begin with navigation and then interact with page elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigation
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;page.goto()&lt;/code&gt; to navigate to a URL. Playwright waits for the page to reach the &lt;code&gt;load&lt;/code&gt; state before proceeding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Interactions
&lt;/h3&gt;

&lt;p&gt;Interacting with elements starts by locating them using Playwright's Locators API. Locators provide a robust way to find elements on the page. Playwright automatically waits for elements to become actionable (e.g., visible, enabled) before performing an action, so you don't need to add explicit waits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a locator for the "Get started" link.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getStartedLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Get started&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Click the located element.&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getStartedLink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Often, this can be condensed into a single line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Get started&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Actions
&lt;/h3&gt;

&lt;p&gt;Here are some common Playwright actions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.check()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Check a checkbox&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.click()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Click an element&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.uncheck()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uncheck a checkbox&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.hover()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hover mouse over an element&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.fill()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fill a form field with text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.focus()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Focus an element&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.press()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Press a single key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.setInputFiles()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pick files for upload&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;locator.selectOption()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Select an option in a dropdown&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Using Assertions
&lt;/h2&gt;

&lt;p&gt;Playwright includes test assertions via the &lt;code&gt;expect&lt;/code&gt; function. Call &lt;code&gt;expect(value)&lt;/code&gt; and use a matcher to define your expectation.&lt;/p&gt;

&lt;p&gt;Playwright offers &lt;strong&gt;async matchers&lt;/strong&gt; that wait for a condition to be met, making tests non-flaky.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This assertion waits until the page title contains "Playwright".&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/Playwright/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Popular Async Assertions
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Assertion&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toBeChecked()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checkbox is checked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toBeEnabled()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Control is enabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toBeVisible()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element is visible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toContainText()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element contains specific text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toHaveAttribute()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element has a specific attribute&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toHaveCount()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List of elements has a given length&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toHaveText()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element matches text (exact or regex)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(locator).toHaveValue()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Input element has a specific value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(page).toHaveTitle()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Page has a specific title (exact or regex)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;expect(page).toHaveURL()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Page has a specific URL (exact or regex)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Playwright also includes generic matchers like &lt;code&gt;toEqual&lt;/code&gt;, &lt;code&gt;toContain&lt;/code&gt;, and &lt;code&gt;toBeTruthy&lt;/code&gt; for immediate synchronous checks. These do not require &lt;code&gt;await&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Synchronous assertion.&lt;/span&gt;
&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test Isolation
&lt;/h2&gt;

&lt;p&gt;Playwright Test ensures strong isolation between tests. Each test receives a fresh environment, thanks to the &lt;code&gt;page&lt;/code&gt; fixture which belongs to an isolated &lt;code&gt;BrowserContext&lt;/code&gt;. A &lt;code&gt;BrowserContext&lt;/code&gt; is equivalent to a brand new browser profile, preventing test interference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tests/example.spec.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@playwright/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// "page" here is isolated for this specific test.&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// "page" in this second test is completely isolated from the first test.&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Test Hooks
&lt;/h2&gt;

&lt;p&gt;Playwright provides various test hooks to organize and manage test execution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;test.describe(name, callback)&lt;/code&gt;: Groups related tests.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;test.beforeEach(callback)&lt;/code&gt;: Runs before each test in the current &lt;code&gt;describe&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;test.afterEach(callback)&lt;/code&gt;: Runs after each test in the current &lt;code&gt;describe&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;test.beforeAll(callback)&lt;/code&gt;: Runs once before all tests in the current &lt;code&gt;describe&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;test.afterAll(callback)&lt;/code&gt;: Runs once after all tests in the current &lt;code&gt;describe&lt;/code&gt; block.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tests/example.spec.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@playwright/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;navigation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Navigate to the starting URL before each test in this group.&lt;/span&gt;
  &lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;main navigation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This test starts at 'https://playwright.dev/' due to beforeEach.&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://playwright.dev/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;navigate to docs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This test also starts at 'https://playwright.dev/'.&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Docs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/.*docs/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>playwright</category>
    </item>
    <item>
      <title>How to Install Playwright: The Ultimate End-to-End Testing Guide</title>
      <dc:creator>Pratham Rathod</dc:creator>
      <pubDate>Sun, 28 Jun 2026 11:36:20 +0000</pubDate>
      <link>https://dev.to/pratham_rathod_a08657abf5/how-to-install-playwright-the-ultimate-end-to-end-testing-guide-14je</link>
      <guid>https://dev.to/pratham_rathod_a08657abf5/how-to-install-playwright-the-ultimate-end-to-end-testing-guide-14je</guid>
      <description>&lt;h1&gt;
  
  
  How to Install Playwright: The Ultimate End-to-End Testing Guide
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn how to install Playwright and set up your first end-to-end testing environment for modern web applications. This comprehensive guide walks you through the installation process using npm, yarn, or pnpm, ensuring a seamless setup for TypeScript or JavaScript projects. Discover how to configure browser binaries for Chromium, WebKit, and Firefox, and leverage the powerful VS Code extension for efficient test development. We cover everything from initializing your project with the playwright.config.ts file to executing your first example test. Explore advanced features like the HTML Test Reporter for detailed debugging, UI Mode for live time-travel debugging, and GitHub Actions integration for continuous integration pipelines. Whether you are working on Windows, Linux, or macOS, this tutorial provides the essential steps to get your automation suite running quickly. We also detail system requirements, including Node.js compatibility and OS support, to ensure your environment is fully optimized for testing success. By following these steps, you will master parallel execution, headless browser testing, and native mobile emulation. Start your journey into reliable, high-performance web testing with Playwright today and streamline your QA workflow with the industry’s most robust automation framework. Elevate your development standards now with our expert installation guide.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Playwright Test is an end-to-end testing framework for modern web applications. It provides a unified solution for testing across Chromium, WebKit, and Firefox with support for parallelization, native mobile emulation, and CI/CD integration.&lt;/p&gt;




&lt;h2&gt;
  
  
  System Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js:&lt;/strong&gt; 22.x, 24.x, or 26.x.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OS:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;Windows 11+ or Windows Server 2019+ (or WSL).&lt;/li&gt;
&lt;li&gt;macOS 14 (Sonoma) or later.&lt;/li&gt;
&lt;li&gt;Debian 12/13, Ubuntu 22.04/24.04/26.04 (x86-64 or arm64).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Run the following command to initialize a new project or add Playwright to an existing project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init playwright@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration Prompts
&lt;/h3&gt;

&lt;p&gt;During installation, you will be prompted to configure the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Language:&lt;/strong&gt; TypeScript (default) or JavaScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test Folder:&lt;/strong&gt; Name of the directory (default: &lt;code&gt;tests&lt;/code&gt; or &lt;code&gt;e2e&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions:&lt;/strong&gt; Recommended for CI integration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser Install:&lt;/strong&gt; Automatically download required binaries (recommended).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;

&lt;p&gt;Playwright creates the following scaffold:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File/Folder&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;playwright.config.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Global configuration (browsers, timeouts, reporters).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tests/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Directory containing your test specifications.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Project dependencies and scripts.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Running Tests
&lt;/h2&gt;

&lt;p&gt;Execute tests using the Playwright CLI. By default, tests run in parallel in headless mode across all configured browsers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Execution Commands
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Run all tests&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npx playwright test&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Run specific file&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npx playwright test tests/example.spec.ts&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Run in headed mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npx playwright test --headed&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Run specific browser&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npx playwright test --project=chromium&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Open UI Mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npx playwright test --ui&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  HTML Reports
&lt;/h3&gt;

&lt;p&gt;After execution, generate and view the detailed HTML report:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright show-report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Maintenance
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Updating Playwright
&lt;/h3&gt;

&lt;p&gt;To update the framework and ensure browser binaries are synchronized:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Update dependency&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; @playwright/test@latest

&lt;span class="c"&gt;# Update browser binaries&lt;/span&gt;
npx playwright &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--with-deps&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Version Check
&lt;/h3&gt;

&lt;p&gt;Verify your current installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx playwright &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Key Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UI Mode:&lt;/strong&gt; Use &lt;code&gt;npx playwright test --ui&lt;/code&gt; for watch mode, live step-by-step debugging, and time-travel inspection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configuration:&lt;/strong&gt; Edit &lt;code&gt;playwright.config.ts&lt;/code&gt; to adjust retries, global timeouts, and environment-specific settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Browser:&lt;/strong&gt; Supports Chromium, Firefox, and WebKit out of the box.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>automation</category>
      <category>testing</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
