🛠️ Real World — E-Commerce Test Scenario
Real World — E-Commerce Test Scenario: Think of a unit test as inspecting each part of a car on the workbench — the brake pad, the fuel pump, the wiring loom — and an E2E test as
Think of a unit test as inspecting each part of a car on the workbench — the brake pad, the fuel pump, the wiring loom — and an E2E test as actually driving the assembled car around the block. Every part can pass its bench inspection while the car still fails to start, because nothing on that bench tested the parts talking to each other. Writing an E2E test scenario follows the same logic as an integration test in Java: instead of isolated units, you verify a full user flow against real dependencies. The e-commerce scenario is the most concrete example of this — login → search → add to cart → checkout is a funnel where each step is a prerequisite for the next. But if unit tests already exist, why do we need time-consuming browser tests? Because a unit test validates the backend's cart logic in isolation; a browser test validates that "the cart icon updated, the count changed, the checkout page opened" — these two are testing entirely different things. In Java, Page Object Model separates test code from the presentation layer by making each page a class; the same pattern appears in Python as page classes + fixtures, and in TypeScript as Playwright's Page Object fixture system. The real QA risk: if only the "add to cart" step is tested but the checkout button is broken, CI stays green while a revenue-killing bug ships to production — and no one finds out until a customer reports it.
Java — E2E Test with Page Object Model
Micro Lab: Selenium — Locator selection
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
Step by Step: Selenium — Locator selection
Check if element has an ID attribute — if yes, use By.ID
If no ID, try stable attributes like data-testid or name
If no attribute, write a CSS selector (.class, #id, tag[attr="val"])
If CSS also fails, write XPath — but keep it as short as possible
After test runs, verify the locator is also stable in CI
What is the Selenium locator strategy selection order?
Python — Pytest + Selenium E2E
Micro Lab: Selenium — Wait strategy
Step by Step: Selenium — Wait strategy