Skip to content

6. Web UI tests: Selenium QA

Most Selenium suites break the same way: someone renames an id, and dozens of find_element(By.ID, ...) calls fail overnight. k11 Selenium QA brings the approach of Chapter 5 to existing Selenium suites in Python (pytest) and Java (JUnit 5 or TestNG, with Maven or Gradle), without a rewrite to Playwright.

Read Chapter 5 first: the story review, verified locators, baselines and healing work the same way. This chapter covers what is different.

What's different from Playwright QA

Selenium QA
Languages Locators come back in your project's language: (By.ID, "email") for Python, By.id("email") for Java
Locator order data-testid, a stable id, name, link text, aria-label, then text-based XPath
Story → test A pytest, JUnit 5 or TestNG skeleton: one test per scenario, explicit waits, driver set-up
Runs pytest, mvn test or gradle test (or their wrappers); each failure names the locator Selenium couldn't find and the line that asked for it, even inside a Page Object
Healing edits every place the locator appears: tests, Page Objects, helpers and @FindBy annotations
Browser Chrome by default (or Edge/Firefox with QA_MCP_BROWSER=edge|firefox); Selenium Manager downloads the matching driver

How a failing locator is detected depends on the language. For pytest, a small plugin records the last locator Selenium could not find (including inside WebDriverWait) and the page the browser was on. For Java, the locator comes from Selenium's own exception text in the JUnit XML reports, and the stack trace shows which Page Object or test asked for it.

Set up

Python 3.10+ and Chrome; for Java projects, Maven or Gradle. Install the plugin:

/plugin install selenium-qa@k11-selenium-qa

The tools: explore_page, check_locator, review_user_story, parse_user_story, write_test, run_tests, capture_baseline, heal_locator, save_login_state. The commands: /story-to-test and /heal-tests.

Healing where the locator lives

The demo app's account page was redesigned: ids renamed, a "View returns" button added next to "View orders", "Edit profile" renamed to "Account settings", the cart message reworded and the page title changed. The suite uses a Page Object:

class AccountPage:
    VIEW_ORDERS = (By.ID, "view-orders")
    OPEN_CART = (By.ID, "cart-btn")
@FindBy(id = "view-orders")
private WebElement viewOrders;

k11-selenium-qa-mcp heal-ci --apply produced this pull request description (trimmed):

1 healed and verified, 0 suggested, 1 reverted, 1 needs review, 0 not found, 1 failure not caused by locators.

Test Where Old locator New locator Confidence Runner-up Re-run
test_shows_my_orders tests/pages/account_page.py:7 (By.ID, "view-orders") (By.ID, "orders-toggle") 82% (By.ID, "returns-toggle") (59%) passed

Needs a person: "Edit profile" → best candidate "Account settings" at 45%, not confident enough to change. (By.ID, "cart-btn") healed at 85%, but the test still failed because the cart message changed too, so the change was reverted.

Not caused by locators: test_has_the_account_title (the page title changed). Untouched: it may be a real bug.

Four outcomes in one report, and each is the right one:

  • Healed and verified: it chose "View orders" over the look-alike "View returns" and fixed it in the Page Object, not the test. In the Java suite the annotation became @FindBy(id = "orders-toggle").
  • Needs review: 45% isn't enough to change code; a person decides.
  • Reverted: a confident heal that didn't make the test pass is undone. The test was failing for a second reason.
  • Not a locator problem: left alone, because a changed page title may be a real bug.

heal-ci

k11-selenium-qa-mcp heal-ci            # dry run
k11-selenium-qa-mcp heal-ci --apply    # edit tests and Page Objects

The steps and options match Playwright QA's (--min-confidence 0.7, --config, --report-dir, --no-verify). The page each test was on comes from .qa-mcp/heal.config.json, the pytest run, or, for Java, the page where that locator's baseline was captured. It also writes GitHub Actions outputs. The repository's docs/heal-locators.yml runs it nightly and opens the pull request.

Evidence for the gate

The same heal-report.json format and the same ui_heal rules as Chapter 5. Release Gate doesn't care which tool healed. Your Selenium suite's own JUnit XML is also evidence, as the junit kind.