PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Media streaming with Selenium

Pick a profile (Kids hides mature titles), browse scrolling rows, save to My List, and drive a custom player — play/pause, seek, ±10s, speed, volume, subtitles, skip intro — with progress that feeds “Continue watching”.

App under test

▶️ StreamBox

URL
/apps/stream
Login
viewer@streambox.tv / Stream@123
Profiles
Amir · Sara · Kids
Skip intro
shown 0:03–0:30
Plans
Basic · Standard · Premium

Scenarios to automate

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

  1. 1

    Account login

    Beginner

    Email + password (sb-login-id, sb-password, sb-login) before the profile picker; sb-logout returns to the login.

  2. 2

    Profile gate

    Beginner

    No profile → profile-picker; switch-profile returns to it. Kids hides A/UA titles and restricts /watch.

  3. 3

    Unique row locators

    Intermediate

    A title can appear in several rows, so cards are open-<row>-<id> (e.g. open-trending-t3).

  4. 4

    Player state

    Intermediate

    player-toggle flips aria-label Play/Pause and data-playing on player; player-time advances.

  5. 5

    Transient button

    Advanced

    skip-intro only exists between 0:03 and 0:30 — wait for it, click, and assert the time jumped to 0:30.

  6. 6

    Range sliders

    Intermediate

    Drive player-seek and player-volume (fill / keyboard / JS); mute toggles the volume to 0.

  7. 7

    Continue watching

    Advanced

    Watch a bit, go home: row-continue shows the title with a progress bar.

  8. 8

    Reorder a list

    Intermediate

    In My List, move-up/down-<id> or drag mylist-item to reorder; order persists.

  9. 9

    Plan change modal

    Beginner

    choose-<plan> shows an upgrade or downgrade note; confirm-plan updates current-plan.

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
StreamBoxPlayerTest.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 ×1 · By.name ×1 · By.linkText ×2 · By.xpath ×2 · By.cssSelector ×2 · data-testid ×13
public class StreamBoxPlayerTest {
  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 watchesATitleAndResumesIt() {
    driver.get(BASE + "/apps/stream");

    // Sign in first
    type(By.id("sb-login-id"), "viewer@streambox.tv");
    type(By.name("sb-password"), "Stream@123");
    click(By.xpath("//button[normalize-space()='Sign in']"));
    click(tid("profile-amir"));
    expectText(tid("active-profile"), "Amir");
    click(tid("open-trending-t3"));
    expectVisible(By.cssSelector("[aria-label='Orbit Nine']"));
    click(tid("mylist-t3"));
    expectText(tid("mylist-t3"), "In My List");
    click(tid("play-t3"));
    expectText(tid("watch-title"), "Orbit Nine");
    select(By.cssSelector("[aria-label='Playback speed']"), "2");
    click(tid("player-toggle"));

    // Skip intro appears a moment after playback starts
    click(By.xpath("//button[normalize-space()='Skip intro']"));
    expectText(tid("player-time"), "00:3");
    click(tid("player-toggle"));
    click(tid("skip-forward-10"));
    expectText(tid("player-time"), "00:4");
    click(By.linkText("Home"));
    expectText(tid("row-continue"), "Orbit Nine");
    click(By.linkText("My List"));
    expectNthText("mylist-item", 0, "Orbit Nine");
  }
}

Practicing another tool?