PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Recruitment with Selenium

Candidates filter jobs and apply through a 4-step form (contact, résumé upload, screening questions, review); recruiters sign in to shortlist, reject with a reason, view résumés and schedule interviews that update the candidate's status.

App under test

💼 HireHub

URL
/apps/jobs
Recruiter
recruiter@hirehub.dev
Password
Hire@123
Résumé
PDF/DOCX ≤ 2 MB

Scenarios to automate

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

  1. 1

    Combined filters

    Beginner

    job-search, job-location, job-experience, job-salary and remote-only narrow job-count.

  2. 2

    Optional URL validation

    Intermediate

    applicant-linkedin can be blank, but a non-linkedin.com/in URL shows error-applicant-linkedin.

  3. 3

    Upload rules

    Intermediate

    resume-file rejects .txt/.jpg and >2 MB; the next step is blocked until a valid file is chosen.

  4. 4

    Screening answers

    Beginner

    q-experience, q-authorized-yes/no and q-notice are all required; review-* shows them.

  5. 5

    Two-role workflow

    Advanced

    Apply as candidate → recruiter shortlists and schedules → application-status shows “Interview scheduled”.

  6. 6

    Conditional actions

    Intermediate

    Only Applied rows show shortlist-*, only Shortlisted rows show schedule-*; Rejected rows show neither.

  7. 7

    Modal validation

    Intermediate

    confirm-interview without day/time/mode shows schedule-error; weekends are disabled.

  8. 8

    Save jobs

    Beginner

    save-job-<id> toggles aria-pressed (bookmark icon).

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
HireHubApplicationTest.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 ×5 · By.linkText ×2 · By.xpath ×4 · By.cssSelector ×1 · data-testid ×15
public class HireHubApplicationTest {
  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));
  }
  // File inputs take an absolute path via sendKeys (fixtures live in src/test/resources).
  void upload(By by, String file) {
    driver.findElement(by).sendKeys(new java.io.File("src/test/resources/" + file).getAbsolutePath());
  }

  @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 appliesForAJobAndGetsAnInterview() {
    driver.get(BASE + "/apps/jobs");
    type(By.id("job-search"), "QA");
    click(By.cssSelector("[aria-label='Remote only']"));
    expectText(tid("job-count"), "2 jobs");
    click(tid("view-job-j1"));
    click(tid("easy-apply"));
    type(By.name("applicant-name"), "Amir Khan");
    type(By.id("applicant-email"), "amir@example.com");
    type(By.name("applicant-phone"), "9876543210");
    click(tid("apply-next"));
    upload(By.id("resume-file"), "resume.pdf");
    click(tid("apply-next"));
    type(By.name("q-experience"), "6");
    click(By.xpath("//button[normalize-space()='Yes']"));
    select(By.id("q-notice"), "30");
    click(tid("apply-next"));
    expectText(tid("review-resume"), "resume.pdf");
    click(By.xpath("//button[normalize-space()='Submit application']"));
    expectText(tid("application-id"), "APP-501");

    // Recruiter side
    click(By.linkText("Recruiter"));
    type(By.name("recruiter-email"), "recruiter@hirehub.dev");
    type(By.id("recruiter-password"), "Hire@123");
    click(By.xpath("//button[normalize-space()='Sign in']"));
    click(tid("job-applicants-j1"));
    click(tid("shortlist-APP-501"));
    click(tid("schedule-APP-501"));
    click(By.cssSelector("[data-testid=\"interview-day\"]:not([disabled])"));
    select(By.name("interview-time"), "11:30");
    click(tid("interview-video"));
    click(By.xpath("//button[normalize-space()='Send invite']"));
    expectText(tid("status-APP-501"), "Interview scheduled");
    click(By.linkText("My applications"));
    expectText(tid("application-status"), "Interview scheduled");
    expectVisible(tid("interview-details"));
  }
}

Practicing another tool?