PracticeQAAutomation logoPracticeQAAutomation
Se

Java · TestNG

Telecom with Selenium

Enter a number for async operator detection, browse plan tabs, compare up to 3 plans, apply a cashback promo, pay and watch the recharge status settle.

App under test

📶 SkyTel

URL
/apps/telecom
Numbers
7/8/9xxxxxxxxx
Other operator
6xxxxxxxxx
Promo
SKY20 (20% cashback)

Scenarios to automate

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

  1. 1

    Operator detection

    Beginner

    After 10 digits a spinner runs ~0.8s, then detected-operator shows the circle. 6xxxxxxxxx is rejected.

  2. 2

    Plan tabs & filter

    Beginner

    Switch plan-tab-*, apply validity-filter and assert the plan-card count.

  3. 3

    Compare limit

    Intermediate

    Tick 4 compare-* boxes: the 4th shows compare-error; compare-button opens compare-table.

  4. 4

    Promo code

    Intermediate

    SKY20 shows cashback in promo-message and summary-cashback; other codes are rejected.

  5. 5

    Payment method validation

    Intermediate

    Pay with no method, a bad UPI ID or an empty wallet to see each error-*.

  6. 6

    Async status

    Advanced

    recharge-status starts as “Pending with operator” and becomes “Successful” ~2.5s later — wait for text, not time.

  7. 7

    Toggles & progress bars

    Advanced

    On My account, read aria-valuenow of usage-* bars and flip addon-* switches (role=switch).

  8. 8

    Complaint form

    Intermediate

    A description under 20 chars fails; a valid one shows complaint-ticket with an SR number.

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
SkyTelRechargeTest.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.xpath ×3 · data-testid ×9
public class SkyTelRechargeTest {
  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 rechargesAPrepaidNumber() {
    driver.get(BASE + "/apps/telecom");
    type(By.id("mobile-number"), "9876543210");
    expectText(tid("detected-operator"), "SkyTel Prepaid");
    click(By.xpath("//button[normalize-space()='Unlimited']"));
    click(tid("select-plan-u2"));
    expectText(tid("selected-plan"), "₹399.00");
    click(By.xpath("//button[normalize-space()='Proceed to pay']"));
    wait.until(urlContains("/apps/telecom/checkout"));
    type(By.name("promo-code"), "SKY20");
    click(By.xpath("//button[normalize-space()='Apply']"));
    expectText(tid("promo-message"), "cashback");
    click(tid("pay-upi"));
    type(By.id("upi-id"), "amir@okbank");
    click(tid("pay-now"));
    expectVisible(tid("recharge-success"));

    // The operator confirms asynchronously
    expectText(tid("recharge-status"), "Successful");
    expectText(tid("recharge-cashback"), "₹50.00");
  }
}

Practicing another tool?