Skip to content
CodeKruPro

Fix URL-only and visible-only assertions

29/99

Module · Reviewing AI-written tests

intermediate

about 40 min

What this lesson teaches

The idea

Ask of each check: what wrong value would still pass it? If the answer is "almost any", the check is decoration.

Why a tester cares

Replacing "the confirmation page loaded" with a check for the exact total the spec gives turns a decorative test into one that catches bugs.

Words you will meet

URL-only check:
a test that stops once it reaches the right page.
Exact assertion:
a check for the precise value the spec gives.
Web-first assertion:
a Playwright check that waits and retries until the value appears.

What you will do

  1. 1Read each assertion
  2. 2Work out the spec values
  3. 3Rewrite the five tests
  4. 4Submit
Jump to practice

The quickest way to improve a generated suite is to look at each assertion and ask: what wrong value would still pass this? If the answer is "almost any", the assertion is decoration.

Two patterns cover most of it:

  • URL-only: the test checks it reached /shop/order/… and stops. A confirmation page with the wrong total has the right URL.
  • Visible-only: to_be_visible() or to_be_attached() on an element whose content is the point.

Replace them with the exact value from the spec, worked out by hand. Playwright's to_have_text waits for the value to appear, so the confirmation page's short loading delay is not a problem; reading the text once and comparing it is.

Your task

Strengthen all five tests. Keep their names and what each one is about. Submit runs them on correct builds, including a slow one, and on builds with wrong data.

Sign in to practise

The lesson is free to read. A free account lets you talk to the practice bots, run your code and save your score. You will come back to this lesson.

ShopLab specShow
ShopLab pricing and checkout rules

Products: Coffee mug (MUG) Rs 299 · Notebook (NOTE) Rs 149 · Wireless headphones (PHONES) Rs 1,999 · Cotton T-shirt (TEE) Rs 499
Each cart line has a quantity from 1 to 10.

Coupons (one per order; applying a new coupon replaces the old one)
  SAVE10   10% off the subtotal, rounded down to the rupee. Needs a subtotal of Rs 500 or more.
           Below that the message is "SAVE10 needs a subtotal of Rs 500 or more." and the discount stays Rs 0.
  FLAT100  Rs 100 off. Needs a subtotal of Rs 999 or more.
  OLD20    Expired. Message: "This coupon has expired."
  Anything else: "Coupon not found."

Shipping: Rs 49 when the subtotal after discount is under Rs 500; free from Rs 500.
Total = subtotal - discount + shipping.

Confirmation page: heading "Order confirmed", the order ID (SL-12345), one line per item such as
"Notebook × 2", and "Total: Rs 1,234". Item lines and the total load a moment after the page.

For tests
  The app's address is in the CK_APP_URL environment variable. Pages: /shop/, /shop/cart, /shop/help.
  POST {CK_APP_URL}/api/cart with {"sku": "MUG", "qty": 2} fills the cart. page.request shares the browser's
  cookies, so a test can set up its cart through the API and then check the page.
  Test IDs (data-testid): message, subtotal, discount, shipping, total, order-id, order-line, order-total.
1

Your code

Write it in
Both are graded the same way.
against ShopLab

How this is checked: When you submit, your tests run against 7 versions of the ShopLab store: 2 correct and 5 with a planted fault. Good tests pass on every correct version and fail on every faulty one. Run tries them on the practice copy first; the result table shows each version.

Core checks earn 50 points and the harder checks the other 50. You can submit as many times as you like.

About this lesson

Playwright assertions that check exact values instead of URL-only and visible-only checks

AI Testing for QA EngineersIntermediateReviewing AI-written tests

How it works

The fastest improvement to a generated suite is to ask of each assertion what wrong value would still pass it. If the honest answer is almost any value, the assertion is decoration.

Two patterns cover most decoration. URL-only checks confirm the test reached the confirmation page and stop, though a page with the wrong total has the right address. Visible-only checks confirm an element exists when its content is the point. Both are replaced by the exact value from the spec, worked out by hand.

Playwright's web-first assertions such as to_have_text retry until the value appears, so pages that fill in details after a short delay need no manual waiting.

About the assignment

Rewrite five weak tests so each asserts the exact values the spec gives for its scenario, and keeps passing on a correct build.

What you will do

  1. For each test, write down the spec value it should assert before touching code.
  2. Replace URL-only and visible-only checks with exact text assertions.
  3. Use the auto-waiting assertion rather than reading the text once.

Common mistakes

  • Reading text once

    Reading a value immediately can catch the page before it loads. The retrying assertion waits.

  • Copying values from the screen

    If the app is wrong, the copied value protects the bug. Work it out from the spec.

In a real test suite

Exact assertions on money, quantities and dates catch the bugs customers notice first. Teams often make them the minimum bar for any checkout test, written into the repository's instruction file.