Java · TestNG
ERP with Selenium
A sortable, paginated inventory grid, purchase orders with dynamic line items and GST totals, and a two-role approval workflow with an audit trail.
App under test
🏭 CoreERP
- URL
- /apps/erp
- Buyer
- buyer / Erp@123
- Manager
- manager / Erp@123
- Tax
- GST 18%
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Role-based access
BeginnerAs buyer, open /apps/erp/approvals and assert access-denied; the manager sees the queue.
- 2
Grid sorting
IntermediateClick sort-qty twice and verify qty-* values are descending; aria-sort reflects the state.
- 3
Filters & pagination
IntermediateCombine inventory-search, warehouse-filter, low-stock-only and page-size; walk page-next.
- 4
Reorder shortcut
Intermediatereorder-<sku> opens a new PO with that item pre-filled on line 0.
- 5
Dynamic line items
AdvancedAdd 3 lines, remove the middle one, and check the remaining line-*-total and po-total.
- 6
PO validation
IntermediateSubmitting with no vendor, no lines, qty 0 or duplicate items shows po-errors and error-*.
- 7
Two-user workflow
AdvancedBuyer submits → logout → manager approves; po-status and po-timeline update.
- 8
Rejection with comment
Advancedreject-po requires a 10+ char reject-comment; it appears as po-comment in the timeline.
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.
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 ×4 · By.name ×3 · By.linkText ×2 · By.xpath ×5 · data-testid ×7
public class CoreErpApprovalTest {
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 raisesAndApprovesAPurchaseOrder() {
driver.get(BASE + "/apps/erp");
// Buyer raises the purchase order
type(By.id("erp-username"), "buyer");
type(By.name("erp-password"), "Erp@123");
click(By.xpath("//button[normalize-space()='Sign in']"));
wait.until(urlContains("/apps/erp/dashboard"));
click(By.linkText("Purchase orders"));
click(tid("new-po"));
select(By.id("po-vendor"), "v2");
click(tid("po-delivery-14"));
click(tid("add-line"));
select(By.name("line-0-item"), "SKU-1004");
type(By.id("line-0-qty"), "25");
expectText(tid("line-0-total"), "8,400.00");
expectText(tid("po-total"), "9,912.00");
click(By.xpath("//button[normalize-space()='Submit for approval']"));
wait.until(urlContains("/apps/erp/po/"));
expectText(tid("po-status"), "Pending approval");
click(By.xpath("//button[normalize-space()='Log out']"));
// Manager approves it
type(By.id("erp-username"), "manager");
type(By.name("erp-password"), "Erp@123");
click(By.xpath("//button[normalize-space()='Sign in']"));
wait.until(urlContains("/apps/erp/dashboard"));
click(By.linkText("Approvals"));
clickNth("approval-review", 0);
click(By.xpath("//button[normalize-space()='Approve']"));
expectText(tid("po-status"), "Approved");
}
}