UI Testing

Two pages to practise web UI testing: a form with elements to find with Selenium or Playwright, and a case study of a button that lost its styling after a stylesheet rebuild.

What a UI test checks

A UI test drives a real browser. It opens a page, finds elements, clicks and types, and then asks what the page shows: is the button visible, does the counter read 3, is the box still in the corner. The thing under test is the rendered document: the HTML after the scripts have run, the box model, and the CSS the browser actually applied, plus the events a user fires.

That is exactly the layer the other two levels cannot see. A unit test calls one function with a fixed input and never builds a document. An API test checks the contract (status code, headers and body) and stops before the renderer. Both are cheap and finish in milliseconds, so you want many of them. A UI test is slower and breaks when a button moves, and it is the only one that fails when a stylesheet is not served, when a cookie banner covers the form, or when a click lands on the wrong element.

The order that works: push the logic down to unit tests, the contract to API tests, and keep UI tests for the few paths a person really walks.

The tools

Two tools cover most browser work. Selenium is the older standard: WebDriver talks to every major browser, and bindings exist for many languages. Playwright ships its own browser builds, waits for an element before acting on it, and keeps a trace of the run for the failure report.

The locators are the same in both: id, class name, tag name, CSS selector, link text. The practice page in this folder has one block per locator type, plus the controls that catch people out — a form, radio buttons, checkboxes, a drop-down, nested tables, and three blocks that differ only by id, by class, or by text alone.

From a locator to a regression test

Four steps, in this order, cover most UI defects and keep the test small.

  1. Find the element by a stable attribute. An id, a name or a data-test attribute survives a redesign; link text works for links. A positional selector such as nth-child is the last resort: the next markup change moves it.
  2. Check the state. Is it visible, enabled, checked, selected, and does it show the expected text? Assert on the element you found, not on the page title: the title can be right while the form below it is broken.
  3. Check the CSS when the look is the point. Read the computed style of the element (width, position, background, border), not the class attribute. A class can be present in the markup even though its rule never reached the browser, and that is how a stylesheet regression hides.
  4. Write one regression test. Open the page, assert the state and the computed value, then revert the fix and watch the test fail. A test that passes on the broken page is checking the wrong property, and a test nobody saw fail is not evidence.

Where to go next

Elements Ui Basic Test Page Page for testing your testing skills in Selenium Webdriver and Playwright Open CSS Testing a button that lost its CSS How to test a button that lost its CSS: check the served stylesheet, computed styles, responsive rules, and add a Playwright regression test. Open