The other day, a friend messaged me, a bit stuck on a Playwright test: “I’m trying to add all 3 products to the cart, but only 2 are getting added, and then it crashes! ๐คฏ” I couldn’t resist helping out and it turned into a fun little debugging adventure. Let me share how we cracked it! ๐ The Scenario It was a practice website with exactly 3 products. My friend’s mission: ๐ Log in ๐ Add all 3 items to the cart ๐ Validate that everything worked smoothly. Sounds simple, right? But the page had a dynamic twist! ๐ The Initial Problem Here’s what he was using at first: const addToCartButtons = page . locator ( 'button:has-text("Add to Cart")' ); for ( let i = 0 ; i < 3 ; i ++ ) { await addToCartButtons . nth ( i ). click (); } But… it would only add 2 items and then fail with a timeout error! Turns out, Playwright was trying to click a button that no longer existed after the page updated. ๐ What Was Happening? When yo...
Whether you're just starting your automation journey or transitioning from manual testing, Playwright is a powerful framework for modern end-to-end testing. In this blog, I’ll walk you through Playwright syntax in detail, including locators , assertions , waits , and more—all in one place. ✅ 1. Installation & Setup npm init -y npm install -D @playwright/test npx playwright install This sets up everything you need, including Chromium, Firefox, and WebKit. ๐งช 2. Basic Test Structure import { test, expect } from '@playwright/test'; test('basic test', async ({ page }) => { await page.goto('https://www.google.com/'); const title = await page.title(); expect(title).toBe('Google'); }); test() defines a test case. expect() is used for assertions. ๐ 3. All About Locators ๐ฏ Playwright-Specific Locators page.getByText('Login'); // matches visible text page.getByRole('button', { name: 'Submit' }); ...