PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Help desk with Selenium

Customers raise tickets (priority set by category); agents work a queue with live SLA countdowns and breach states, bulk-assign, reply with canned responses and formatting, add internal notes, and resolve with a required reason.

App under test

🎧 DeskFlow

URL
/apps/helpdesk
Agent
agent@deskflow.dev
Password
Desk@123
SLA
Urgent 30m · High 1h · Med 4h · Low 24h

Scenarios to automate

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

  1. 1

    Derived priority

    Beginner

    Choosing ticket-category shows which priority the ticket will get (Technical → High).

  2. 2

    Live SLA timers

    Intermediate

    sla-<id> counts down each second; breached tickets have data-breached="true" and red text.

  3. 3

    Queue filters

    Beginner

    status-filter, priority-filter, owner-filter and queue-search combine; assert queue-count.

  4. 4

    Bulk assign

    Intermediate

    select-all-tickets → bulk-assign-me updates every assignee-<id> cell.

  5. 5

    Toolbar formatting

    Intermediate

    Select text in reply-text, click format-bold; the sent message renders <strong>.

  6. 6

    Internal notes

    Intermediate

    internal-note switch → message has data-internal="true" and doesn't count as a first response.

  7. 7

    First response

    Advanced

    Sending a public reply stops the SLA timer (“Responded”) and moves Open → Pending.

  8. 8

    Resolution rule

    Intermediate

    Setting ticket-status to Resolved without resolution-category shows ticket-error.

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
DeskFlowTicketTest.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 ×4 · By.name ×3 · By.xpath ×5 · By.cssSelector ×3 · data-testid ×10
public class DeskFlowTicketTest {
  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 raisesATicketAndResolvesItAsAnAgent() {
    driver.get(BASE + "/apps/helpdesk");
    type(By.id("requester-name"), "Grace Lee");
    type(By.name("requester-email"), "grace@globex.com");
    select(tid("ticket-category"), "technical");
    type(By.id("ticket-subject"), "Cannot export report to PDF");
    type(tid("ticket-description"), "The export button spins forever and nothing downloads.");
    click(By.xpath("//button[normalize-space()='Submit ticket']"));
    expectText(tid("ticket-created"), "#1041");

    // Switch to the agent side
    click(tid("agent-login-link"));
    type(By.name("agent-email"), "agent@deskflow.dev");
    type(By.id("agent-password"), "Desk@123");
    click(By.xpath("//button[normalize-space()='Sign in']"));
    wait.until(urlContains("/apps/helpdesk/queue"));
    expectNthText("open-ticket", 0, "Cannot export report");
    expectText(tid("sla-1041"), "00:5");
    clickNth("open-ticket", 0);
    click(By.xpath("//button[normalize-space()='Assign to me']"));
    expectText(tid("ticket-toast"), "Assigned");
    select(By.cssSelector("[aria-label='Insert canned response']"), "greeting");
    click(tid("send-reply"));
    expectNthText("message", 1, "thanks for reaching out");
    click(By.cssSelector("[aria-label='Internal note']"));
    type(By.cssSelector("[aria-label='Reply']"), "Reproduced on staging, escalating to dev.");
    click(tid("send-reply"));
    expectNthText("message", 2, "Reproduced on staging");
    select(By.name("ticket-status"), "Resolved");
    click(By.xpath("//button[normalize-space()='Update ticket']"));
    expectVisible(tid("ticket-error"));
    select(By.id("resolution-category"), "bug-fixed");
    click(By.xpath("//button[normalize-space()='Update ticket']"));
    expectText(tid("ticket-status-badge"), "Resolved");
  }
}

Practicing another tool?