Module 8 · Automation foundations
What to automate, and how to keep it reliable
Choosing checks with a good return, and avoiding flaky tests.
About 10 min reading and 5 min practice (estimates)
Loading progress…
Read
Learning objectives
- Pick good candidates for automation.
- Explain the test pyramid and why most checks shouldn't go through the UI.
- Recognise common causes of flaky tests.
Explanation
Automation is software that checks software. It pays off for checks that are repeated often, are stable, and matter: critical journeys (sign-in, checkout), calculations with many cases, and regressions you never want to see again. It is a poor fit for one-off checks, rapidly changing screens, and judgement calls like "is this confusing?" — that's where exploratory testing shines.
The test pyramid suggests many fast unit tests, fewer API/integration tests, and a small number of end-to-end UI tests. UI tests are the slowest and most fragile, so use them for a few key journeys and test detailed rules at lower levels.
Reliability
- Isolation: each test creates its own data and doesn't depend on another test's leftovers or order.
- Waiting: wait for a condition (an element is visible, a request finished), never for a fixed number of seconds.
- Stable selectors: find elements the way users do — by role and accessible name — not by fragile CSS paths.
- Meaningful assertions: check the outcome that matters, with a clear failure message.
- A flaky test (passes and fails without code changes) erodes trust; fix or quarantine it quickly.
Example: deciding for Dar Al Souq
| Check | Automate? | Level |
|---|---|---|
| Discount rounding for 30 price combinations | Yes | Unit |
| Order is created with the right totals | Yes | API |
| A shopper can add an item and reach checkout | Yes, one journey | UI end-to-end |
| New banner design looks balanced | No | Human review |
| Arabic copy reads naturally | No | Human review |
Common mistakes
- Automating everything through the UI.
- Using fixed sleeps ("wait 5 seconds") instead of waiting for conditions.
- Letting tests share data, so one failure causes many.
- Ignoring flaky tests until nobody trusts the suite.
Try
Practise what you just read. Answers are checked here; nothing is graded publicly or counts toward Bug Arena.
Exercise
A UI test sometimes fails because it clicks "Pay" before the total has finished updating. What is the best fix?
Review
Check yourself — you should now be able to:
- Pick good candidates for automation.
- Explain the test pyramid and why most checks shouldn't go through the UI.
- Recognise common causes of flaky tests.
References
Continue
When you’re ready, mark the lesson complete in the Try step and move on.
Marked as read when you reach the end of the lesson.