E-commerce Automation Practice

Automate a realistic storefront β€” search products, manage the cart, enter an address, and place an order β€” with Selenium, Cypress, or Playwright.

20 products
Laptop Pro
Laptop Pro
β˜…β˜…β˜…β˜…Β½4.6 (1,284)
$1200
Wireless Mouse
Wireless Mouse
β˜…β˜…β˜…β˜…β˜†4.3 (842)
$25
Keyboard RGB
Keyboard RGB
β˜…β˜…β˜…β˜…Β½4.5 (973)
$80
Headphones Noise Cancelling
Headphones Noise Cancelling
β˜…β˜…β˜…β˜…Β½4.7 (2,109)
$150
External SSD 1TB
External SSD 1TB
β˜…β˜…β˜…β˜…Β½4.8 (1,550)
$180
Monitor 4K
Monitor 4K
β˜…β˜…β˜…β˜…β˜†4.4 (688)
$350
Coca Cola 250ml
Coca Cola 250ml
β˜…β˜…β˜…β˜…β˜†4.2 (5,321)
$1
Mango Drink
Mango Drink
β˜…β˜…β˜…β˜…β˜†4.0 (1,892)
$2

How to Automate This E-commerce Page

A full shopping journey β€” search a product, set a quantity, add to cart, review the cart, enter a shipping address, pay, and see the order confirmation. It is ideal for practising dynamic, per-product locators, an off-canvas cart, and a multi-step checkout.

The same scenario written for two popular frameworks. These use the stable id and data-testid locators documented in the cheat sheet below.

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

test('search, add to cart, and check out', async ({ page }) => {
  await page.goto('https://www.qapractice.com/practice-ecommerece-website');

  // Product id 2 = "Wireless Mouse"
  await page.getByTestId('quantity-2').fill('2');
  await page.getByTestId('add-to-cart-2').click();

  await page.getByTestId('ecom-cart-button').click();
  await page.getByTestId('ecom-proceed-to-buy').click();

  // Shipping address
  await page.getByTestId('ecom-address-name').fill('Ada Lovelace');
  await page.getByTestId('ecom-address-street').fill('1 Analytical Ave');
  await page.getByTestId('ecom-address-city').fill('London');
  await page.getByTestId('ecom-address-state').fill('LDN');
  await page.getByTestId('ecom-address-zip').fill('EC1A');
  await page.getByTestId('ecom-save-address').click();

  // Payment
  await page.getByTestId('ecom-card-number').fill('4111111111111111');
  await page.getByTestId('ecom-expiry').fill('12/30');
  await page.getByTestId('ecom-cvv').fill('123');
  await page.getByTestId('ecom-buy-now').click();

  await expect(page.getByTestId('ecom-order-success'))
    .toContainText('Order Successful');
});
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;

public class EcommerceTest {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    driver.get("https://www.qapractice.com/practice-ecommerece-website");

    // Product id 2 = "Wireless Mouse"
    driver.findElement(By.id("quantity-2")).clear();
    driver.findElement(By.id("quantity-2")).sendKeys("2");
    driver.findElement(By.cssSelector("[data-testid='add-to-cart-2']")).click();

    driver.findElement(By.id("ecom-cart-button")).click();
    wait.until(ExpectedConditions.elementToBeClickable(
        By.id("ecom-proceed-to-buy"))).click();

    driver.findElement(By.id("ecom-address-name")).sendKeys("Ada Lovelace");
    driver.findElement(By.id("ecom-address-street")).sendKeys("1 Analytical Ave");
    driver.findElement(By.id("ecom-address-city")).sendKeys("London");
    driver.findElement(By.id("ecom-address-state")).sendKeys("LDN");
    driver.findElement(By.id("ecom-address-zip")).sendKeys("EC1A");
    driver.findElement(By.id("ecom-save-address")).click();

    driver.findElement(By.id("ecom-card-number")).sendKeys("4111111111111111");
    driver.findElement(By.id("ecom-expiry")).sendKeys("12/30");
    driver.findElement(By.id("ecom-cvv")).sendKeys("123");
    driver.findElement(By.id("ecom-buy-now")).click();

    String msg = wait.until(ExpectedConditions.visibilityOfElementLocated(
        By.id("ecom-order-success"))).getText();
    assert msg.contains("Order Successful");

    driver.quit();
  }
}

Every interactive element on this page exposes a stable id and/or data-testid so your scripts don't depend on brittle positions or styling.

Elementiddata-testidPlaywright locatorSelenium locator
Search boxecom-searchecom-searchgetByTestId('ecom-search').fill('mouse')By.id("ecom-search")
Category filter buttonβ€”ecom-category-<name>getByTestId('ecom-category-electronics')By.cssSelector("[data-testid='ecom-category-electronics']")
Sort dropdownecom-sortecom-sortgetByTestId('ecom-sort').selectOption('price-asc')new Select(driver.findElement(By.id("ecom-sort")))
Open a product (view details)β€”view-product-<id>getByTestId('view-product-2')By.cssSelector("[data-testid='view-product-2']")
Product detail containerβ€”ecom-product-detailgetByTestId('ecom-product-detail')By.cssSelector("[data-testid='ecom-product-detail']")
Back to products (from detail)β€”ecom-back-to-productsgetByTestId('ecom-back-to-products')By.cssSelector("[data-testid='ecom-back-to-products']")
Pagination: a page numberβ€”ecom-page-<n>getByTestId('ecom-page-2')By.cssSelector("[data-testid='ecom-page-2']")
Pagination: next / previousβ€”ecom-page-next / ecom-page-prevgetByTestId('ecom-page-next')By.cssSelector("[data-testid='ecom-page-next']")
Cart button (opens cart)ecom-cart-buttonecom-cart-buttongetByTestId('ecom-cart-button')By.id("ecom-cart-button")
Quantity for a productquantity-<id>quantity-<id>getByTestId('quantity-2')By.id("quantity-2")
Add to cart for a productβ€”add-to-cart-<id>getByTestId('add-to-cart-2')By.cssSelector("[data-testid='add-to-cart-2']")
Remove item from cartβ€”remove-from-cart-<id>getByTestId('remove-from-cart-2')By.cssSelector("[data-testid='remove-from-cart-2']")
Proceed to Buyecom-proceed-to-buyecom-proceed-to-buygetByTestId('ecom-proceed-to-buy')By.id("ecom-proceed-to-buy")
Address: full nameecom-address-nameecom-address-namegetByTestId('ecom-address-name')By.id("ecom-address-name")
Address: streetecom-address-streetecom-address-streetgetByTestId('ecom-address-street')By.id("ecom-address-street")
Address: cityecom-address-cityecom-address-citygetByTestId('ecom-address-city')By.id("ecom-address-city")
Address: stateecom-address-stateecom-address-stategetByTestId('ecom-address-state')By.id("ecom-address-state")
Address: ZIPecom-address-zipecom-address-zipgetByTestId('ecom-address-zip')By.id("ecom-address-zip")
Save Address & continueecom-save-addressecom-save-addressgetByTestId('ecom-save-address')By.id("ecom-save-address")
Card numberecom-card-numberecom-card-numbergetByTestId('ecom-card-number')By.id("ecom-card-number")
Expiry dateecom-expiryecom-expirygetByTestId('ecom-expiry')By.id("ecom-expiry")
CVVecom-cvvecom-cvvgetByTestId('ecom-cvv')By.id("ecom-cvv")
Buy Nowecom-buy-nowecom-buy-nowgetByTestId('ecom-buy-now')By.id("ecom-buy-now")
Order-success headingecom-order-successecom-order-successgetByTestId('ecom-order-success')By.id("ecom-order-success")

Use these as a checklist to build your automation suite. Download them as a Markdown file to keep alongside your test project.

IDScenarioStepsExpected Result
TC01Add a product to the cart
  1. Set a quantity for a product
  2. Click Add to Cart
  3. Open the cart
The product appears in the cart with the chosen quantity, and the cart badge count increases.
TC02Search filters products
  1. Type "mouse" in the search box
Only products matching the search term are shown, and the result count updates.
TC02bCategory filter
  1. Click the "Fashion" category button
Only Fashion products are listed and the count reflects the category.
TC02cSort by price
  1. Choose "Price: Low to High" in the sort dropdown
Products are re-ordered from cheapest to most expensive.
TC02dPagination
  1. Click page 2 in the pagination
The next set of products is shown; Previous becomes enabled.
TC02eOpen a product page
  1. Click a product name or image
The product detail page opens with description, rating, price, and Add to Cart.
TC03Remove an item from the cart
  1. Add a product
  2. Open the cart
  3. Click Remove
The item is removed and the cart total updates.
TC04Proceed to Buy disabled when cart empty
  1. Open the cart with no items
The Proceed to Buy button is disabled.
TC05Full checkout happy path
  1. Add a product
  2. Proceed to Buy
  3. Fill the address, save
  4. Fill payment, Buy Now
An "Order Successful!" confirmation with the purchased items is shown.
TC06Cart total is correct
  1. Add product A (qty 2) and product B (qty 1)
The cart total equals A.priceΓ—2 + B.price.
TC07Quantity minimum
  1. Try to set a product quantity below 1
The quantity input enforces a minimum of 1.
TC08Payment validation
  1. Reach payment
  2. Submit with empty/invalid card details
Validation errors are shown and the order is not completed.