← Back to Tutorials

6. End-to-End Exercises

Product Purchase Flow

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
});

Autosuggest Dropdowns

test('handle autosuggest dropdown', async ({ page }) => {
  await page.goto('https://example.com/search');
  await page.fill('#search', 'Play');
  await page.waitForSelector('.suggestions');
  await page.getByRole('option', { name: 'Playwright' }).click();
  await expect(page).toHaveURL(/.*Playwright/);
});
✏️ 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.