Java · TestNG
NGO & donations with Selenium
Campaigns with progress bars, amount chips or a custom amount, one-time vs monthly, an optional fee top-up, PAN required at ₹2,000+ for an 80G certificate, anonymous and in-honour gifts, and pause/cancel for monthly giving.
App under test
💛 GiveHope
- URL
- /apps/donate
- Minimum
- ₹100
- PAN needed
- ₹2,000 and above
- Fee cover
- 2.5%
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Progress bars
Beginnerprogress-<id> is role=progressbar; read aria-valuenow and compare with raised-<id> / goal.
- 2
Chips vs custom
BeginnerTyping custom-amount clears the selected amount-* chip (aria-pressed=false) and vice versa.
- 3
Threshold field
Intermediatedonor-pan and pan-required only appear once the total reaches ₹2,000; the PAN format is validated.
- 4
Fee maths
Intermediatecover-fee adds 2.5%: ₹2,500 → fee-amount ₹62.50, donation-total ₹2,562.50.
- 5
Minimum amount
BeginnerA custom amount under ₹100 shows error-amount.
- 6
Conditional field
Beginnerin-honour (switch) reveals honoree-name, which is then required.
- 7
Recurring management
Intermediatepause-recurring → recurring-status Paused → resume/cancel via cancel-recurring-modal; year-total updates.
- 8
80G availability
IntermediateReceipts with a PAN show download-80g; smaller gifts show no-80g.
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 ×1 · By.xpath ×3 · By.cssSelector ×1 · data-testid ×13
public class GiveHopeDonationTest {
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 setsUpAMonthlyDonationAndPausesIt() {
driver.get(BASE + "/apps/donate");
click(By.xpath("//button[normalize-space()='education']"));
click(By.linkText("Donate"));
expectText(tid("campaign-title"), "Books for 500 rural classrooms");
click(By.xpath("//button[normalize-space()='Monthly']"));
click(tid("amount-2500"));
check(By.id("cover-fee"));
expectText(tid("fee-amount"), "₹62.50");
expectText(tid("donation-total"), "₹2,562.50");
type(By.name("donor-name"), "Amir Khan");
type(By.id("donor-email"), "amir@example.com");
type(By.name("donor-phone"), "9876543210");
expectVisible(tid("pan-required"));
type(By.id("donor-pan"), "ABCDE1234F");
click(By.cssSelector("[aria-label='Give in honour of someone']"));
type(By.name("honoree-name"), "Grandma Fatima");
click(tid("pay-upi"));
type(By.id("donate-upi"), "amir@okbank");
click(tid("donate-now"));
expectText(tid("receipt-amount"), "₹2,562.50/month");
expectVisible(tid("download-80g"));
click(tid("manage-giving"));
expectText(tid("recurring-status"), "Active");
expectText(tid("year-total"), "₹30,750.00");
click(By.xpath("//button[normalize-space()='Pause']"));
expectText(tid("recurring-status"), "Paused");
}
}