PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Healthcare with Selenium

Pick a specialty, filter doctors, choose a day (Sundays closed) and a free time slot, fill new or existing patient details, then reschedule or cancel.

App under test

🩺 MediCare+

URL
/apps/clinic
Existing patient
P-1001
Video consult
20% off
Closed
Sundays

Scenarios to automate

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

  1. 1

    Specialty & filters

    Beginner

    Toggle specialty-*, combine filter-gender, filter-fee and filter-available-today; assert doctor-count.

  2. 2

    Sort order

    Intermediate

    sort-doctors “Lowest fee” must order doctor-fee values ascending.

  3. 3

    Disabled dates

    Intermediate

    Sunday chips in appointment-day are disabled; pick the first enabled day with :not([disabled]).

  4. 4

    Booked slots

    Intermediate

    Slots with data-available="false" are disabled; choose a free one and check slot-summary.

  5. 5

    Existing patient lookup

    Intermediate

    patient-existing + P-1001 shows patient-found; any other ID shows patient-not-found.

  6. 6

    Conditional insurance fields

    Beginner

    has-insurance reveals insurance-provider and policy-number, both validated.

  7. 7

    Reschedule

    Advanced

    Move an appointment in reschedule-modal and assert appointment-slot changed.

  8. 8

    Cancel

    Advanced

    cancel-appt-<id> → confirm-cancel-appointment sets appointment-status to Cancelled.

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
MediCareBookingTest.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 ×5 · By.name ×2 · By.xpath ×2 · data-testid ×9
public class MediCareBookingTest {
  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 booksAVideoConsultation() {
    driver.get(BASE + "/apps/clinic");
    click(tid("specialty-cardiology"));
    expectText(tid("doctor-count"), "2 doctors");
    clickNth("book-doctor", 0);
    expectText(tid("doctor-title"), "Ananya Rao");
    click(tid("type-video"));

    // First open day (Sundays are disabled), then the first free slot
    click(By.cssSelector("[data-testid=\"appointment-day\"]:not([disabled])"));
    click(By.cssSelector("[data-testid=\"slot\"][data-available=\"true\"]"));
    expectText(tid("slot-summary"), "Video");
    click(By.xpath("//button[normalize-space()='Continue']"));
    click(tid("patient-new"));
    type(By.id("patient-name"), "Amir Khan");
    type(By.name("patient-age"), "36");
    select(By.id("patient-gender"), "male");
    type(By.name("patient-phone"), "9876543210");
    type(By.id("patient-email"), "amir@example.com");
    type(By.id("symptoms"), "Occasional chest discomfort after exercise");
    check(By.id("consent"));
    click(By.xpath("//button[normalize-space()='Confirm appointment']"));
    expectVisible(tid("appointment-confirmed"));
    expectText(tid("appointment-id"), "APT-");
    expectText(tid("appointment-type"), "Video consult");
  }
}

Practicing another tool?