Real World Example

Net Banking Payment Flow

In banking and e-commerce payment tests (Razorpay, PayU or a bank's own gateway), one checkout can touch every topic in this module: a confirm dialog, a payment iframe, and a bank OTP page in a new window.

driver.findElement(By.id("checkout")).click();
wait.until(ExpectedConditions.alertIsPresent()).accept();             // "Proceed to payment?"

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("payment-frame")));
driver.findElement(By.id("netbanking-test-bank")).click();
String main = driver.getWindowHandle();
driver.findElement(By.id("pay-now")).click();
driver.switchTo().defaultContent();

wait.until(ExpectedConditions.numberOfWindowsToBe(2));
for (String h : driver.getWindowHandles()) if (!h.equals(main)) driver.switchTo().window(h);
driver.findElement(By.id("otp")).sendKeys("123456");                 // test bank OTP in the QA environment
driver.findElement(By.id("submit-otp")).click();

driver.switchTo().window(main);
String status = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("order-status"))).getText();
System.out.println("Order status: " + status);

Example

Output:

Run NetBankingPaymentTest.main()

Example output

Order status: Payment successful. Order ORD-1004 confirmed.

Note on OTPs

Real OTPs cannot be automated. QA environments use test banks with a fixed OTP, or the team reads the OTP from a test API. Never automate against real bank accounts.