PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Logistics with Selenium

Pincode serviceability lookups that auto-fill the city, volumetric vs chargeable weight maths, service rules, COD limits, a barcode label and a live tracking timeline.

App under test

📦 ShipFast

URL
/apps/logistics
Pincodes
400001, 560001, 110001…
Demo AWB
SF1234567890
COD limit
₹20,000

Scenarios to automate

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

  1. 1

    Pincode lookup

    Beginner

    After 6 digits a spinner runs, then sender-city shows the city; unknown pincodes show “Not serviceable”.

  2. 2

    Weight maths

    Intermediate

    30×20×15 cm → volumetric-weight 1.8 kg; chargeable-weight is the higher value rounded up to 0.5 kg.

  3. 3

    Service rules

    Intermediate

    service-same-day is disabled unless both pincodes are in the same city.

  4. 4

    COD limit

    Intermediate

    Declared value above ₹20,000 with pay-cod shows error-payment.

  5. 5

    Live quote

    Beginner

    freight-charge and shipment-total update as weight, service, insurance and payment change.

  6. 6

    Label & barcode

    Intermediate

    awb-number is SF + 10 digits; download-label saves a text file named after it.

  7. 7

    Polling a timeline

    Advanced

    A new shipment's current-status moves Booked → Picked up → In transit every ~4s; wait for text.

  8. 8

    Unknown AWB

    Beginner

    Tracking a random AWB shows track-error; SF1234567890 shows a delivered journey.

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
ShipFastShipmentTest.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 ×6 · By.name ×6 · By.linkText ×1 · By.xpath ×1 · data-testid ×13
public class ShipFastShipmentTest {
  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 booksAndTracksAShipment() {
    driver.get(BASE + "/apps/logistics");
    click(tid("ship-now"));
    wait.until(urlContains("/apps/logistics/ship"));
    type(By.id("sender-name"), "Amir Khan");
    type(By.name("sender-phone"), "9876543210");
    type(By.id("sender-pincode"), "400001");
    expectText(tid("sender-city"), "Mumbai");
    type(By.name("sender-address"), "12 Marine Drive, Churchgate");
    type(By.id("receiver-name"), "Sara Khan");
    type(By.name("receiver-phone"), "9812345678");
    type(tid("receiver-pincode"), "560001");
    expectText(By.id("receiver-city"), "Bengaluru");
    type(By.name("receiver-address"), "44 MG Road, Ashok Nagar");
    click(tid("package-parcel"));
    type(By.id("weight"), "2");
    type(By.name("length"), "30");
    type(tid("width"), "20");
    type(By.id("height"), "15");
    expectText(tid("volumetric-weight"), "1.8 kg");
    expectText(tid("chargeable-weight"), "2 kg");
    type(By.name("declared-value"), "2500");
    click(tid("service-express"));
    click(tid("pay-prepaid"));
    expectText(tid("shipment-total"), "220.00");
    click(By.xpath("//button[normalize-space()='Book shipment']"));
    expectVisible(tid("shipment-booked"));
    expectText(tid("awb-number"), "SF");
    click(By.linkText("Track shipment"));
    expectText(tid("tracking-result"), "Mumbai → Bengaluru");
  }
}

Practicing another tool?