Lesson 16 / الدرس 16
Project: automate one real journey / مشروع: أتمتة رحلة حقيقية واحدة
One journey, automated properly: chosen for a reason you can defend, written so it does not flake, and proved to fail when it should. This is the piece of work that shows you can be trusted with a suite.
رحلة واحدة، مؤتمتة كما ينبغي: مختارة لسبب تستطيع الدفاع عنه، ومكتوبة بحيث لا تتقلّب، ومثبَت أنها ترسب حين ينبغي. وهذا هو العمل الذي يُظهر أنه يمكن ائتمانك على مجموعة.
Pick one journey through any site you are entitled to test — this one, your own work, or a service with a public test environment. Something with three or four steps and a result you can assert: search and open a result, take a quiz and see a score, fill a form and get a confirmation. One journey done properly beats five half-written every time, and it is what you will be asked to talk through.
What to hand in
-
Why this journey. One paragraph: how often it runs, how stable it is, what it would cost if it broke. This is the lesson on what not to automate, applied to a real choice. لماذا هذه الرحلة. فقرة واحدة: كم مرة تجري، وكم هي مستقرة، وكم ستكلّف لو انكسرت. وهذا درس ما لا يُؤتمت مطبَّقًا على اختيار حقيقي.
-
The test itself, in arrange / act / assert blocks, with a name that reads as a sentence and locators chosen by role, label or test id. الاختبار نفسه، في كتل تجهيز وفعل وتوكيد، باسم يُقرأ جملةً ومحدِّدات مختارة بالدور أو التسمية أو معرّف الاختبار.
-
Proof it can fail. Break it deliberately — change the expected value — and record the failure message. A test never seen red is not finished. دليل أنه يستطيع الرسوب. اكسره عمدًا — غيّر القيمة المتوقعة — وسجّل رسالة الرسوب. فالاختبار الذي لم يُرَ أحمر قط لم يكتمل.
-
What you left manual, and why. Appearance, wording, anything you could not assert honestly. ما تركته يدويًا، ولماذا. المظهر، والصياغة، وكل ما لم تستطع توكيده بصدق.
What a finished answer looks like
// The shape of a finished answer.
//
// Why this journey: opening a lesson from a course page is on every student's
// first visit, has not changed in months, and if it broke the site would be
// unusable. Stable + high traffic + high cost = worth automating.
test('a visitor can open a lesson from its course page', async ({ page }) => {
// Arrange
await page.goto('/course/testing');
// Act
await page.getByRole('link', { name: /What testing actually is/ }).click();
// Assert
await expect(page).toHaveURL(/lesson\/testing\/what-testing-is/);
await expect(page.getByRole('heading', { level: 1 }))
.toContainText('What testing actually is');
});
// Proved it fails: changed the expected URL to /lesson/testing/nonsense and got
// Expected pattern: /lesson\/testing\/nonsense/
// Received string: "http://localhost:8000/lesson/testing/what-testing-is"
//
// Left manual: whether the lesson is readable in Arabic, and whether the
// heading is legible at 320px. Neither can be asserted honestly.
Check yourself / اختبر نفسك
1. Why must the project include proof that the test can fail?
An assertion that cannot fail is green forever and reads like a real check. Deliberately breaking it is the only cheap proof it has teeth — and showing that proof is what separates a finished test from a hopeful one.
2. Why does the project ask what you deliberately left manual?
Appearance, wording and usability cannot be asserted honestly, and pretending otherwise produces green tests that guard nothing. Naming them tells a reader exactly how much the passing suite is worth.
3. Which is an acceptable target to automate against for this project?
A script sends requests far faster than a person and cannot judge when to stop. Automating against a system you have no permission to test can be unlawful regardless of intent, and being a student is not a defence.
Score / النتيجة: 0 / 3