test('complete purchase on SauceDemo', async ({ page }) => {
await page.goto('https://www.saucedemo.com');
await page.fill('#user-name', 'standard_user');
await page.fill('#password', 'secret_sauce');
await page.click('#login-button');
// Add item to cart
await page.click('#add-to-cart-sauce-labs-backpack');
await page.click('.shopping_cart_link');
// Checkout
await page.click('#checkout');
await page.fill('#first-name', 'John');
await page.fill('#last-name', 'Doe');
await page.fill('#postal-code', '12345');
await page.click('#continue');
await page.click('#finish');
// Verify order
await expect(page.locator('.complete-header')).toHaveText('Thank you for your order!');
});
Order History Validation
test('validate order appears in history', async ({ page }) => {
// Login and place order
// Navigate to order history
await page.click('#menu_button');
await page.click('text=All Items');
// ... purchase steps ...
// Validate order ID visible in history
await page.click('#menu_button');
await page.click('text=About');
// Assert order exists
});
✏️ Exercise: Write a Playwright script to log in to SauceDemo, add an item to cart, complete checkout, and validate the order ID appears in the confirmation page.