Lesson 2 / الدرس 2

What not to automate / ما لا يُؤتمت

Every automated test costs something forever: it has to be written, run, and repaired every time the product changes. Deciding what to leave alone is the part of automation that most teams skip, and it is why their suites collapse in year two.

كل اختبار آلي يكلّف شيئًا إلى الأبد: فلا بد أن يُكتب ويُجرى ويُصلَح كلما تغيّر المنتج. واختيار ما يُترك هو الجزء الذي تتخطاه معظم الفرق من الأتمتة، وهو سبب انهيار مجموعاتها في السنة الثانية.

An automated test is not free once it is written. It runs on every build, so it costs minutes; it breaks whenever the thing it touches changes, so it costs repairs; and every repair is a chance to weaken it until it passes again. A suite is a garden, not a warehouse. Teams that automate everything they can end up maintaining a suite instead of testing a product.

Leave these to a person

Do not automateBecause
Does it look rightA machine compares pixels; it cannot tell ugly from unusual
Is this wording clearClarity is a judgement about a reader, and there is no assertion for it
A feature still being designedIt will change five times; you will repair the test five times
Something run once, everWriting it costs more than running it by hand
A test nobody can make failIf you cannot break it deliberately, it is checking nothing
Exploratory workIt is designed while it runs, which is the one thing a script cannot do

None of these are "too hard to automate". They are things where automating removes the judgement that was doing the work.

The question to ask

Before automating anything, ask: how many times will this run before the thing it tests changes? A sign-in flow that has been stable for two years will run a thousand times — automate it. A checkout being redesigned this quarter will run twelve times and be rewritten — test it by hand and automate it when it settles. The answer is not about importance; it is about stability.

// Automate: stable, high value, runs on every build.
test('a signed-out visitor cannot open the dashboard', async ({ page }) => {
  await page.goto('/dashboard');
  await expect(page).toHaveURL(/sign-in/);
});

// Do NOT automate: this is a judgement, and the assertion is a lie.
test('the dashboard looks professional', async ({ page }) => {
  await page.goto('/dashboard');
  await expect(page.locator('.card')).toHaveCount(4); // ...that is not what was asked
});
The second test is the trap, and it is extremely common. Somebody wanted to check the dashboard looks right, could not express that, and settled for counting cards. It will now pass forever while the page rots, and fail the day a fifth card is added on purpose.

Check yourself / اختبر نفسك

1. Which question best decides whether to automate a test?

2. A test called "the dashboard looks professional" asserts there are four cards. What is wrong?

3. An automated test has failed three times running, each time because the product legitimately changed. What should you do?