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

  1. 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.
  2. 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.
  3. Proof it can fail. Break it deliberately — change the expected value — and record the failure message. A test never seen red is not finished.
  4. 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.
The comments are half the deliverable. A test with no stated reason and no proof it can fail is a piece of code; with them it is an argument, and the argument is what a reviewer is actually assessing.

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

1. Why must the project include proof that the test can fail?

2. Why does the project ask what you deliberately left manual?

3. Which is an acceptable target to automate against for this project?