PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Manufacturing with Selenium

A live machine dashboard with status filters and OEE meters, work orders whose bill of materials is checked against stock (shortages block release), a start → complete lifecycle, and quality inspection with tolerance-based pass/fail.

App under test

⚙️ FactoryOS

URL
/apps/factory
Impeller stock
40 units
QC spec
25.00 ± 0.05 mm …
WO numbers
WO-1001 …

Scenarios to automate

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

  1. 1

    Changing data

    Intermediate

    machine-card data-status changes every ~4s; assert counts add up (count-*) rather than specific states.

  2. 2

    Meters

    Beginner

    oee-* use role=meter with aria-valuenow; avg-oee is the mean of all machines.

  3. 3

    BOM maths

    Intermediate

    Pump × 50 → required-bearing 100, required-impeller 50 (stock 40) → shortage-impeller shows −10.

  4. 4

    Blocked action

    Intermediate

    release-wo with a shortage shows wo-error naming the part; wo-qty-dec10 clears it (materials-ok).

  5. 5

    Lifecycle

    Beginner

    start-<id> → In progress → complete-<id> → Completed; buttons change with status.

  6. 6

    Tolerance checks

    Advanced

    25.06 mm fails (Out of tolerance) while 25.05 passes; any defect checkbox forces FAIL.

  7. 7

    Incomplete inspection

    Beginner

    submit-inspection before all measurements shows qc-error; qc-result stays Pending.

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
FactoryOsWorkOrderTest.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 ×2 · By.name ×2 · By.linkText ×2 · By.xpath ×6 · By.cssSelector ×2 · data-testid ×11
public class FactoryOsWorkOrderTest {
  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 releasesAWorkOrderAndPassesQC() {
    driver.get(BASE + "/apps/factory");
    expectVisible(tid("machine-grid"));
    click(By.linkText("Work orders"));
    click(tid("new-work-order"));
    select(By.id("wo-product"), "pump");
    type(By.name("wo-qty"), "50");
    expectText(tid("required-impeller"), "50");
    expectText(tid("shortage-impeller"), "−10");
    click(By.xpath("//button[normalize-space()='Release work order']"));
    expectText(tid("wo-error"), "Impeller");
    click(tid("wo-qty-dec10"));
    expectVisible(tid("materials-ok"));
    select(By.id("wo-line"), "Line B");
    clickNth("wo-due", 3);
    click(By.xpath("//button[normalize-space()='Urgent']"));
    click(By.xpath("//button[normalize-space()='Release work order']"));
    expectText(tid("wo-status-WO-1001"), "Released");
    click(By.xpath("//button[normalize-space()='Start']"));
    click(By.xpath("//button[normalize-space()='Complete']"));
    expectText(tid("wo-status-WO-1001"), "Completed");
    click(By.linkText("Quality"));
    type(By.cssSelector("[aria-label='Bore diameter measured']"), "25.02");
    type(By.name("qc-length"), "119.9");
    type(By.cssSelector("[aria-label='Weight measured']"), "2.43");
    expectText(tid("qc-result"), "PASS");
    click(By.xpath("//button[normalize-space()='Record inspection']"));
    expectText(tid("inspection-id"), "QC-");
  }
}

Practicing another tool?