PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Fantasy sports with Selenium

Pick 11 players under a 100-credit budget with a 7-per-team cap and role minimums/maximums — every blocked + explains why — then choose captain and vice-captain, save, and see your leaderboard rank.

App under test

🏏 FantasyXI

URL
/apps/fantasy
Login
player11 / Play@123
Budget
100 credits · 11 players
Per team
max 7
Multipliers
C 2× · VC 1.5×

Scenarios to automate

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

  1. 1

    Account login

    Beginner

    Username + password (fx-login-id, fx-password, fx-login). Teams and rank belong to the signed-in account; fx-logout signs out.

  2. 2

    Counters

    Beginner

    Each pick updates players-selected, credits-left, count-IND/AUS and role-count-*.

  3. 3

    Disabled with a reason

    Intermediate

    When a rule blocks a player, pick-<id> is disabled and its title / block-<id> text says why.

  4. 4

    Budget rule

    Intermediate

    Pick expensive players until “Not enough credits” appears.

  5. 5

    Team cap

    Intermediate

    After 7 IND players, every other IND pick is blocked.

  6. 6

    Role limits

    Advanced

    Role max and “leave room for other roles' minimums” both block picks — test both.

  7. 7

    Captain rules

    Intermediate

    The same player can't be both C and VC; projected-points recalculates with multipliers.

  8. 8

    Countdown lock

    Advanced

    lock-countdown-* ticks every second; the semi-final shows locked-m2 and a disabled button.

  9. 9

    Leaderboard sort

    Beginner

    sort-points toggles order and aria-sort; your team is highlighted with my-rank.

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
FantasyXiTeamTest.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 ×2 · By.name ×1 · By.linkText ×1 · By.xpath ×2 · data-testid ×25
public class FantasyXiTeamTest {
  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 buildsAValidXIAndChecksItsRank() {
    driver.get(BASE + "/apps/fantasy");

    // Sign in first
    type(By.id("fx-login-id"), "player11");
    type(By.name("fx-password"), "Play@123");
    click(By.xpath("//button[normalize-space()='Sign in']"));
    click(tid("create-team-m1"));
    click(tid("role-wk"));
    click(tid("pick-ind-wk1"));
    click(tid("role-bat"));
    click(tid("pick-ind-b2"));
    click(tid("pick-ind-b4"));
    click(tid("pick-aus-b1"));
    click(tid("pick-aus-b4"));
    click(tid("role-ar"));
    click(tid("pick-ind-ar1"));
    click(tid("pick-aus-ar2"));
    click(tid("role-bowl"));
    click(tid("pick-ind-bo1"));
    click(tid("pick-ind-bo3"));
    click(tid("pick-aus-bo3"));
    click(tid("pick-ind-bo4"));
    expectText(tid("players-selected"), "11/11");
    expectText(tid("credits-left"), "0.0");
    expectText(tid("count-IND"), "7");
    click(tid("next-captain"));
    click(tid("captain-ind-ar1"));
    click(tid("vc-aus-b1"));
    expectText(tid("projected-points"), "865");
    type(By.id("team-name"), "Amir XI");
    click(By.xpath("//button[normalize-space()='Save team']"));
    expectText(tid("team-points"), "865");
    click(By.linkText("Leaderboard"));
    expectText(tid("my-rank"), "#6");
  }
}

Practicing another tool?