Dynamic content & waits

Each exercise needs a different waiting strategy. If you reach for a fixed sleep (waitForTimeout), your test will either be slow or flaky. Wait for the state you need instead.

1. Delayed element

Beginner

Click Start. A spinner shows for a random 2–5 seconds, then a heading appears.

Expected: the spinner appears, then the finish heading becomes visible with the greeting and the spinner is gone. Your test must pass whether the load takes 2 or 5 seconds.

Show me how

2. Hidden vs removed

Beginner

One paragraph is hidden with CSS (still in the page), the other is removed from the DOM completely.

I am sometimes hidden.

I am sometimes removed.

Expected: after toggling, hidden-target is not visible but still exists (count 1), while removed-target doesn't exist at all (count 0). Toggling again brings both back.

Show me how

3. Enable / disable

Beginner

The input starts disabled. Clicking the button "calls a server" for 2 seconds, then enables it.

Expected: the input is disabled at first, enabled after the click (message It's enabled!), and you can type into it.

Show me how

4. Add / remove elements

Beginner

Each click adds a Delete button; clicking one removes it.

Expected: three clicks create three buttons (added-1 to added-3); deleting the second leaves two, and added-2 no longer exists.

Show me how

5. Dynamic IDs

Beginner

This button gets a new random id on every page load, so a recorded #btn-… selector breaks next time.

Expected: your test clicks the button reliably on any load, and the message confirms the click with the current id. Reloading gives a different id.

Show me how

6. Progress bar

Advanced

The bar gains 1% every 100 ms. Stop it at exactly 75%.

0%

Expected: the result reads Stopped at 75%. Perfect! every time you run the test, not just sometimes.

Show me how

7. Text changes

Beginner

The job status goes Pending → Processing → Done over about 4 seconds.

Status: Idle

Expected: your test sees all three statuses in order and finishes as soon as the status is Done.

Show me how

8. Covered button

Intermediate

For 3 seconds after the page loads, an overlay sits on top of the button and swallows clicks.

Please wait…

Expected: the click lands on the real button (message Button clicked!), not on the overlay, without forcing it.

Show me how

9. Load more

Intermediate

Each click loads 5 more items after about a second, up to 20 in total.

    Expected: after four batches there are exactly 20 items, and the button is disabled with the text No more items.

    Show me how