lecture 10 of 170 completed

Checking a whole list

Sort both lists when order does not matter. When order is the point, never sort what you read.

What you'll learn

  • Why a count proves how many items there are, not which ones
  • When to sort both lists before you compare them
  • Why a sort test must never sort the values it reads
  • Why two filters must be tested together, in both orders

A bookshop's stock page has a Sort by price button. Your test reads the prices before the click and sorts them. That is the order you expect. It clicks the button and reads the prices again. Then it sorts those too, to be safe, and compares the two lists. The test passes. It also passes when the button does nothing at all.

The second sort is the bug. Once your test sorts what it read, the list is in order whatever the page showed. The test can no longer fail on order, and order is the one thing it was meant to check.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →