PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Food delivery with Selenium

Filter restaurants, add dishes with quantity steppers, customise a pizza in a modal, handle a replace-cart prompt, add tip and coupon, then watch the order move live and rate it.

App under test

🍔 FoodDash

URL
/apps/food
Login
not required
Coupon
FEAST50 (min ₹299)
Free delivery
above ₹499

Scenarios to automate

Work top to bottom — each one adds a new technique.

  1. 1

    Filters & switch

    Beginner

    Combine cuisine-* chips, veg-only (role=switch), food-search and restaurant-sort; assert restaurant-count.

  2. 2

    ADD becomes a stepper

    Beginner

    add-<item> turns into <item>-dec / <item>-qty / <item>-inc; decreasing to 0 brings ADD back.

  3. 3

    Customisation modal

    Intermediate

    Pick size-* and topping-* (max 3 — the 4th is disabled); custom-total updates live.

  4. 4

    Replace cart prompt

    Intermediate

    Adding from a second restaurant opens replace-cart-modal; keep-cart vs confirm-replace.

  5. 5

    Coupon rules

    Intermediate

    FEAST50 under ₹299 shows how much more to add; above it caps the discount at ₹100.

  6. 6

    Bill maths

    Advanced

    Verify bill-items, bill-discount, bill-delivery (free ≥ ₹499), bill-taxes (5%) and bill-total with a tip.

  7. 7

    Live tracking

    Advanced

    order-status moves Order placed → Preparing → Out for delivery → Delivered every ~3s.

  8. 8

    Rate & reorder

    Intermediate

    After delivery, rate-* + submit-rating shows rating-thanks; reorder-<id> refills the cart.

Sample Selenium suite

A working starting point that finds elements every way Selenium can — by role, label, text, id, name, CSS, XPath and data-testid — so you practice them all. Pick your language, switch to data-testid only to compare, or try your own in the Locator Playground.

Language
FoodDashOrderTest.java
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.Map;
import org.openqa.selenium.support.ui.*;
import java.time.Duration;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;

// Locators in this suite: By.id ×1 · By.name ×1 · By.xpath ×2 · By.cssSelector ×1 · data-testid ×21
public class FoodDashOrderTest {
  static final String BASE = "https://www.practiceqaautomation.com";
  WebDriver driver;
  WebDriverWait wait;

  // Small helpers: every action takes a By and waits for its element first (no Thread.sleep).
  By tid(String id) { return By.cssSelector("[data-testid='" + id + "']"); }
  WebElement ready(By by) { return centre(wait.until(elementToBeClickable(by))); }
  void click(By by) { ready(by).click(); }
  WebElement nth(String id, int n) { return centre(wait.until(numberOfElementsToBeMoreThan(tid(id), n)).get(n)); }
  void clickNth(String id, int n) { nth(id, n).click(); }
  // Scroll to the middle of the screen first: Selenium only scrolls an element to the edge,
  // where a sticky header or a fixed bottom bar can cover it (ElementClickInterceptedException).
  WebElement centre(WebElement e) {
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView({block: 'center', inline: 'nearest'})", e);
    return e;
  }
  void type(By by, String text) { ready(by).sendKeys(text); }
  void select(By by, String value) { new Select(ready(by)).selectByValue(value); }
  void check(By by) { WebElement e = ready(by); if (!e.isSelected()) e.click(); }
  void expectText(By by, String text) { wait.until(textToBePresentInElementLocated(by, text)); }
  void expectVisible(By by) { wait.until(visibilityOfElementLocated(by)); }
  void expectNthText(String id, int n, String text) {
    wait.until(d -> d.findElements(tid(id)).size() > n && d.findElements(tid(id)).get(n).getText().contains(text));
  }

  @BeforeMethod
  public void setUp() {
    ChromeOptions options = new ChromeOptions();
    // Turn off Chrome's "Save password?" and "password found in a data breach" pop-ups: after a
    // login they take the keyboard and mouse away from the page, so later typing and clicks are lost.
    options.setExperimentalOption("prefs", Map.of(
        "credentials_enable_service", false,
        "profile.password_manager_enabled", false,
        "profile.password_manager_leak_detection", false));
    driver = new ChromeDriver(options);
    wait = new WebDriverWait(driver, Duration.ofSeconds(10));
  }

  @AfterMethod(alwaysRun = true)
  public void tearDown() { driver.quit(); }

  @Test
  public void ordersACustomisedPizzaAndTracksIt() {
    driver.get(BASE + "/apps/food");
    click(By.xpath("//button[normalize-space()='Pizza']"));
    expectText(tid("restaurant-count"), "1 restaurant");
    click(tid("open-restaurant-r3"));
    expectText(tid("restaurant-title"), "Slice of Napoli");

    // Customise a Margherita: medium + olives
    click(tid("add-r3i1"));
    click(tid("size-medium"));
    check(tid("topping-olives"));
    expectText(tid("custom-total"), "₹489");
    click(tid("add-customized"));
    click(tid("add-r3i4"));
    click(By.cssSelector("[aria-label='Add one Garlic Bread']"));
    expectText(tid("r3i4-qty"), "2");
    expectText(tid("cart-count"), "3");
    click(tid("view-cart"));
    wait.until(urlContains("/apps/food/checkout"));
    type(By.id("promo-code"), "FEAST50");
    click(By.xpath("//button[normalize-space()='Apply']"));
    expectText(tid("promo-message"), "applied");
    click(tid("tip-20"));
    expectText(tid("bill-delivery"), "FREE");
    expectText(tid("bill-total"), "₹741");
    click(tid("address-home"));
    type(By.name("delivery-phone"), "9876543210");
    click(tid("pay-upi"));
    click(tid("place-order"));
    expectVisible(tid("order-placed"));

    // The status advances on its own — wait for text, never sleep
    expectText(tid("order-status"), "Preparing");
  }
}

Practicing another tool?