Skip to content

Exercise 3: Mutation Testing with Pitest & End-to-End Testing with Playwright

In this exercise, you will explore advanced software verification techniques at two opposite ends of the testing pyramid: Mutation Testing (evaluating test suite thoroughness at the unit and integration level) and End-to-End (E2E) Testing (verifying functional user journeys across the browser and application stack).

Mutation testing evaluates the fault-detection capability of your test suite by injecting deliberate artificial faults (mutants) into your bytecode and observing whether your tests fail (kill the mutant). Meanwhile, End-to-End testing validates that the entire integrated application—from HTTP routing and database persistence to HTML rendering and client-side interactions—functions correctly from the perspective of an end user driving a real web browser.

You will work with a fork of the Spring Petclinic web application (branch csui). Unlike the REST-only API variant used in Exercises 1 and 2, this project provides a full server-rendered web UI built with Spring MVC and Thymeleaf templates. Make sure you are not continuing the spring-petclinic-rest codebase!

Getting Started

Complete the following prerequisites before starting the exercise:

  1. Ensure you are enrolled in the SQA (PMPL) course and have an active account on GitLab CSUI.
  2. Verify that the required development tools are installed on your workstation:
    • Git
    • Java JDK version 17
    • Node.js (optional, recommended for launching Playwright Trace Viewer via npx)
    • Modern terminal environment and IDE (IntelliJ IDEA, VS Code, etc.)
  3. Open the Spring Petclinic project on GitLab CSUI and fork it into your personal namespace.
  4. Clone your fork locally and switch to the csui branch:
    1
    2
    3
    4
    git clone git@gitlab.cs.ui.ac.id:<YOUR_USERNAME>/spring-petclinic.git
    cd spring-petclinic
    git switch csui
    git pull origin csui
    
  5. Create a new working branch for this exercise:
    1
    git switch -c task/3-mutation-and-e2e
    
  6. Verify that the existing unit and integration test suite compiles and runs cleanly:
    1
    ./mvnw clean test
    

Part 1: Mutation Testing with Pitest

Task 1: Configure Pitest

Pitest is the state-of-the-art mutation testing system for Java and the JVM. To integrate Pitest into Spring Petclinic, configure the Pitest Maven Plugin in pom.xml.

  1. Open pom.xml and locate the <properties> block. Add the properties for Pitest plugin version, JUnit 5 plugin dependency, and mutation engine:

    1
    2
    3
    4
    5
    6
    <properties>
      <!-- ... existing properties ... -->
      <maven.pitest-plugin.version>1.20.3</maven.pitest-plugin.version>
      <maven.pitest-junit5-plugin.version>1.2.3</maven.pitest-junit5-plugin.version>
      <pitest.mutationEngine>gregor</pitest.mutationEngine>
    </properties>
    
  2. Locate the <build><plugins> section in pom.xml. Add the pitest-maven plugin configuration:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <plugin>
      <groupId>org.pitest</groupId>
      <artifactId>pitest-maven</artifactId>
      <version>${maven.pitest-plugin.version}</version>
      <configuration>
        <mutationEngine>${pitest.mutationEngine}</mutationEngine>
        <timestampedReports>false</timestampedReports>
        <targetClasses>
          <!-- Mandatory classes to analyse -->
          <param>org.springframework.samples.petclinic.owner*</param>
          <!-- You can add more classes to analyse by adding more <param> element 
               E.g., <param>org.springframework.samples.petclinic.vet*</param> to analyse classes in vet package
          -->
        </targetClasses>
      </configuration>
      <dependencies>
        <dependency>
          <groupId>org.pitest</groupId>
          <artifactId>pitest-junit5-plugin</artifactId>
          <version>${maven.pitest-junit5-plugin.version}</version>
        </dependency>
      </dependencies>
    </plugin>
    
  3. Commit your configuration change to git:

    1
    2
    git add pom.xml
    git commit -m "Configure pitest-maven plugin"
    

Task 2: Run Pitest and Generate the Mutation Report

With Pitest configured, execute mutation coverage analysis using the Maven wrapper:

  1. Run the following command from the repository root:

    1
    ./mvnw test-compile org.pitest:pitest-maven:mutationCoverage
    

    Note: test-compile Maven task ensures that test and production classes are compiled and up to date before Pitest runs the mutation goal.

  2. Once the execution completes, open the generated HTML report in your browser. You will see metrics that we covered in the lectures, such as line coverage, mutation coverage, and test strength.

  3. Remember the RIPR model we covered in earlier lectures to reason about why mutants survive:
    • Reachability: The test must execute the mutated statement.
    • Infection: The mutated statement must produce an erroneous internal state.
    • Propagation: The erroneous state must propagate to an observable program state (e.g., return value or thrown exception).
    • Revealability: The test assertion must inspect and detect the incorrect state.

Task 3: Guided Mutant Analysis

Examine the report for org.springframework.samples.petclinic.owner.OwnerController. Notice a surviving mutant generated by MathMutator at line 144 of OwnerController.java inside findPaginatedForOwnersLastName:

1
2
3
4
5
6
7
// Line 142 in OwnerController.java
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
    int pageSize = 5;
    int validatedPage = Math.max(page, 1);
    Pageable pageable = PageRequest.of(validatedPage - 1, pageSize); // Line 144: Subtraction replaced by addition
    return owners.findByLastNameStartingWith(lastname, pageable);
}

The MathMutator replaced validatedPage - 1 with validatedPage + 1. Under this mutant, requesting page 1 causes the controller to request page 2 (0-indexed page index 2) from the repository rather than page 0.

Look at the tests covering this method in OwnerControllerTests.java and PetClinicIntegrationTests.java. There are two issues with the tests at it current version:

  1. In OwnerControllerTests, repository interactions are stubbed with Mockito:
    1
    when(this.owners.findByLastNameStartingWith(anyString(), any(Pageable.class))).thenReturn(tasks);
    
    Notice the argument matcher: any(Pageable.class). Because Mockito accepts any Pageable instance regardless of its page number or size, it returns tasks whether validatedPage - 1 or validatedPage + 1 was passed. The infection in pageable never affects the mock's return value!
  2. In PetClinicIntegrationTests.java, the ownerList() test checks:
    1
    2
    3
    4
    5
    6
    @Test
    void ownerList() {
        RestTemplate template = builder.baseUri("http://localhost:" + port).build();
        ResponseEntity<String> result = template.exchange(RequestEntity.get("/owners?lastName=").build(), String.class);
        assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
    }
    
    The test only checks that the HTTP status code is 200 OK. It does not assert which page of owners is rendered in the HTML view.

To kill this mutant, we must strengthen our test assertions so that an incorrect Pageable argument causes test failure.

Open src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java. Then, specify the expected PageRequest directly in verify() or when():

1
2
3
4
import org.springframework.data.domain.PageRequest;
// Omitted for brevity ...

verify(this.owners).findByLastNameStartingWith(anyString(), eq(PageRequest.of(0, 5)));

After updated the tests, rerun Pitest:

1
./mvnw test-compile org.pitest:pitest-maven:mutationCoverage

Reopen target/pit-reports/index.html and verify that the MathMutator at line 144 in OwnerController.java is now KILLED.

Commit your changes:

1
2
git add src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java
git commit -m "Kill mutant on OwnerController pagination"

Task 4: DIY Mutant Analysis & Elimination

Now it is your turn to independently analyse and kill a surviving mutant. Open the Pitest report and inspect org.springframework.samples.petclinic.owner.Owner. Then, take a look around lines 178-183:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public void addVisit(Integer petId, Visit visit) {
    Assert.notNull(petId, "Pet identifier must not be null!"); // Line 178: Removed call
    Assert.notNull(visit, "Visit must not be null!");          // Line 179: Removed call

    Pet pet = getPet(petId);

    Assert.notNull(pet, "Invalid Pet identifier!");            // Line 183: Removed call

    pet.addVisit(visit);
}

There is a surviving mutant that was produced by VoidMethodCallMutator mutation operator, which removes the calls to Assert.notNull() statements. The survival reason should be pretty obvious. If you check the existing test cases, there are no test cases that attempted to pass null or non-existing pet to the SUT. Therefore, your task is to add unit tests that provide null inputs and invalid pet IDs to kill the mutants.

Part 2: End-to-End (E2E) Testing with Playwright

Take a look at the following code snippets that use mock test from the Spring Petclinic codebase:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// Some annotations, classes, and attributes are omitted for brevity.
class OwnerControllerTests {

    @Autowired
    private MockMvc mockMvc;

    @MockitoBean
    private OwnerRepository owners;

    @Test
    void initCreationForm() throws Exception {
        mockMvc.perform(get("/owners/new"))
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("owner"))
            .andExpect(view().name("owners/createOrUpdateOwnerForm"));
    }
    // The rest of the tests ...
}

Unit and integration tests verify components within isolated mock environments (such as Spring's MockMvc). From the example above, developers can verify the behaviour of the controller component without deploying the entire application on a runtime environment. While fast and informative, mock tests cannot detect issues stemming from real browser engines, dynamic HTML/CSS rendering, form submission workflows, or browser-level navigation.

End-to-End (E2E) testing verifies the application by controlling a headless or headful web browser instance that interacts with the live application. There are three commonly mentioned browser automation framework, such as Selenium, Cypress, and Playwright. In this exercise, we will use Playwright, which is maintained by Microsoft. Playwright provides the following:

  • Multi-browser support (Chromium, Firefox, WebKit).
  • Automatic waiting (no arbitrary Thread.sleep or polling loops).
  • Resilient locators prioritising accessibility (ARIA roles, labels, text) over brittle XPath or CSS selectors.
  • Comprehensive debugging tools, including the interactive Playwright Trace Viewer.

Task 1: Configure Playwright Java in Maven & Base Test Architecture

In this task, you will add the Playwright Java dependency to your pom.xml and construct an abstract base test class that boots the Spring Boot application on a dynamic port and sets up Playwright's JUnit 5 extension.

1. Add Playwright Dependency

Open pom.xml and add com.microsoft.playwright:playwright inside the <dependencies> block:

1
2
3
4
5
6
<dependency>
    <groupId>com.microsoft.playwright</groupId>
    <artifactId>playwright</artifactId>
    <version>1.50.0</version>
    <scope>test</scope>
</dependency>

2. Create Base E2E Test Class

Create a base class named AbstractPetClinicE2ETests under src/test/java/org/springframework/samples/petclinic/e2e/AbstractPetClinicE2ETests.java.

This class serves two purposes:

  1. It boots the Spring Boot application on a random available port using @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT).
  2. It activates the official Playwright JUnit 5 extension via @UsePlaywright, providing dependency injection of Playwright fixtures (Page, BrowserContext, etc.) directly into test methods, configured to run headless and record traces on failure.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: BSD-3-Clause
package org.springframework.samples.petclinic.e2e;

import com.microsoft.playwright.junit.Options;
import com.microsoft.playwright.junit.OptionsFactory;
import com.microsoft.playwright.junit.UsePlaywright;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import java.nio.file.Paths;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@UsePlaywright(AbstractPetClinicE2ETests.CustomOptions.class)
public abstract class AbstractPetClinicE2ETests {

    @LocalServerPort
    protected int localPort;

    protected String getBaseUrl() {
        return "http://localhost:" + localPort;
    }

    public static class CustomOptions implements OptionsFactory {
        @Override
        public Options setOptions() {
            return new Options()
                .setHeadless(true)
                .setTrace(Options.Trace.RETAIN_ON_FAILURE)
                .setRecordTrace(new Options.RecordTrace()
                    .setDir(Paths.get("target/playwright-traces")));
        }
    }
}

Task 2: Baseline Smoke Test

Before writing complex multi-page interactions, create a smoke test to verify automated browser launch and basic elements in the home page.

Create PetClinicSmokeE2ETests.java under src/test/java/org/springframework/samples/petclinic/e2e/:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// SPDX-License-Identifier: BSD-3-Clause
package org.springframework.samples.petclinic.e2e;

import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

class PetClinicSmokeE2ETests extends AbstractPetClinicE2ETests {

    @Test
    @DisplayName("Verify home page")
    void testHomePageSmoke(Page page) {
        page.navigate(getBaseUrl() + "/");

        assertThat(page).hasTitle("PetClinic :: a Spring Framework demonstration");
        assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Welcome"))).isVisible();
        assertThat(page.locator("img.img-responsive")).isVisible();
    }
}

Run the smoke test:

1
./mvnw test -Dtest=PetClinicSmokeE2ETests

Confirm that the test suite boots Spring Boot, opens Chromium headlessly, and passes all assertions.

Task 3: Implement Page Object Model (POM) Pattern

Writing raw locator calls (page.locator(...), page.getByRole(...)) directly inside test methods leads to code duplication and high maintenance cost whenever the UI templates change.

The Page Object Model (POM) is a design pattern that abstracts web pages into reusable Java classes. Each Page Object encapsulates the page's HTML structure, locators, and actions. Test classes interact only with the high-level methods of Page Objects.

1. Locator Strategy

If you have read the XPath section in BDD workshop, it shows a challenge in locating an element in a client-side rendered page produced by library such as React or Angular. Locating an element can be done using an inspector tool provided by the browser, then obtain the XPath expression to be given to a locator function provided by browser automation framework.

However, XPath could be not stable. Especially in a client-side rendered pages where HTML elements could be updated dynamically. Instead of using XPath, modern browser automation framework such as Playwright encourages using user-facing locators reflecting how users and assistive technologies perceive the page, rather than brittle implementation details like CSS classes or internal DOM IDs.

The following is a table summarises the locator strategies, which generated by generative AI (Gemini 4 Hydrogen):

Strategy Playwright API Why Prefer?
Role (ARIA) page.getByRole(AriaRole.BUTTON, ...) Matches semantic elements (<button>, <a>, <input type="submit">), enforcing accessibility standards.
Label page.getByLabel("Last name") Pairs form inputs with their corresponding <label>, resilient against ID changes.
Text page.getByText("Owner Information") Matches visible text content displayed to users.
CSS / XPath page.locator(".btn.btn-primary") Avoid unless necessary: brittle; frequently breaks during styling refactors.

2. Implement FindOwnersPage

Create FindOwnersPage.java in package org.springframework.samples.petclinic.e2e.pages:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: CC0-1.0
package org.springframework.samples.petclinic.e2e.pages;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;

public class FindOwnersPage {

    private final Page page;
    private final Locator lastNameInput;
    private final Locator findOwnerButton;
    private final Locator addOwnerButton;

    public FindOwnersPage(Page page) {
        this.page = page;
        this.lastNameInput = page.getByLabel("Last name");
        this.findOwnerButton = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Find Owner"));
        this.addOwnerButton = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Add Owner"));
    }

    public void navigate(String baseUrl) {
        page.navigate(baseUrl + "/owners/find");
    }

    public void searchByLastName(String lastName) {
        lastNameInput.fill(lastName);
        findOwnerButton.click();
    }

    public void clickAddOwner() {
        addOwnerButton.click();
    }
}

3. Implement OwnerInformationPage

Create OwnerInformationPage.java in package org.springframework.samples.petclinic.e2e.pages:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: CC0-1.0
package org.springframework.samples.petclinic.e2e.pages;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;

public class OwnerInformationPage {

    private final Page page;
    private final Locator heading;
    private final Locator ownerTable;
    private final Locator editOwnerButton;
    private final Locator addNewPetButton;

    public OwnerInformationPage(Page page) {
        this.page = page;
        this.heading = page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Owner Information"));
        this.ownerTable = page.locator("table.table-striped").first();
        this.editOwnerButton = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Edit Owner"));
        this.addNewPetButton = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Add New Pet"));
    }

    public Locator getHeading() {
        return heading;
    }

    public String getOwnerName() {
        return ownerTable.locator("tr").filter(new Locator.FilterOptions().setHasText("Name")).locator("td").innerText().trim();
    }

    public String getAddress() {
        return ownerTable.locator("tr").filter(new Locator.FilterOptions().setHasText("Address")).locator("td").innerText().trim();
    }

    public String getCity() {
        return ownerTable.locator("tr").filter(new Locator.FilterOptions().setHasText("City")).locator("td").innerText().trim();
    }

    public String getTelephone() {
        return ownerTable.locator("tr").filter(new Locator.FilterOptions().setHasText("Telephone")).locator("td").innerText().trim();
    }

    public boolean hasPet(String petName) {
        return page.locator("table.table-striped").nth(1).locator("dd")
            .filter(new Locator.FilterOptions().setHasText(petName)).count() > 0;
    }

    public void clickAddNewPet() {
        addNewPetButton.click();
    }
}

4. Implement Search Flow Tests

In Spring Petclinic, searching for owners exhibits two distinct navigational behaviours:

  • Single result: Searching for a last name matching exactly one owner (e.g., Franklin) immediately redirects to /owners/{id}.
  • Multiple results: Searching for a last name shared by multiple owners (e.g., Davis, matching Betty Davis and Harold Davis) renders a selection table (owners/ownersList.html).

Create FindOwnersE2ETests.java under src/test/java/org/springframework/samples/petclinic/e2e/:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: CC0-1.0
package org.springframework.samples.petclinic.e2e;

import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.samples.petclinic.e2e.pages.FindOwnersPage;
import org.springframework.samples.petclinic.e2e.pages.OwnerInformationPage;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FindOwnersE2ETests extends AbstractPetClinicE2ETests {

    @Test
    @DisplayName("Single owner search redirects directly to Owner Information page (Franklin)")
    void testSearchSingleOwnerRedirect(Page page) {
        FindOwnersPage findOwnersPage = new FindOwnersPage(page);
        findOwnersPage.navigate(getBaseUrl());
        findOwnersPage.searchByLastName("Franklin");

        OwnerInformationPage ownerPage = new OwnerInformationPage(page);
        assertThat(ownerPage.getHeading()).isVisible();
        assertEquals("George Franklin", ownerPage.getOwnerName());
        assertEquals("110 W. Liberty St.", ownerPage.getAddress());
        assertEquals("Madison", ownerPage.getCity());
        assertEquals("6085551023", ownerPage.getTelephone());
        assertTrue(ownerPage.hasPet("Leo"));
    }

    @Test
    @DisplayName("Multi-owner search displays list and navigates upon selection (Davis)")
    void testSearchMultiOwnerSelection(Page page) {
        FindOwnersPage findOwnersPage = new FindOwnersPage(page);
        findOwnersPage.navigate(getBaseUrl());
        findOwnersPage.searchByLastName("Davis");

        // Verify that the multiple owners table is displayed
        assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Owners"))).isVisible();
        assertThat(page.locator("table#owners")).isVisible();

        // Click on Betty Davis link to navigate to her details
        page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Betty Davis")).click();

        OwnerInformationPage ownerPage = new OwnerInformationPage(page);
        assertThat(ownerPage.getHeading()).isVisible();
        assertEquals("Betty Davis", ownerPage.getOwnerName());
        assertEquals("638 Cardinal Ave.", ownerPage.getAddress());
    }
}

Execute both tests:

1
./mvnw test -Dtest=FindOwnersE2ETests

Task 4: Trace Viewer Diagnostics

When an E2E test fails in a headless CI/CD environment, standard console logs often do not provide sufficient context to determine why an element was not visible or why a redirect failed.

Playwright's Trace Viewer records a holistic diagnostic bundle for each test run:

  • Action-by-action timeline with step durations.
  • Visual before/after snapshots of the DOM at each action.
  • Live DOM tree inspector with computed styles and locator pickers.
  • Console logs, network requests, responses, and execution stack traces.

1. Trace Retention Configuration

In Task 5, we configured AbstractPetClinicE2ETests with:

1
2
.setTrace(Options.Trace.RETAIN_ON_FAILURE)
.setRecordTrace(new Options.RecordTrace().setDir(Paths.get("target/playwright-traces")))

With RETAIN_ON_FAILURE, Playwright records traces in memory during test execution. If the test passes, the trace is discarded, avoiding unnecessary disk consumption. If any assertion fails or an unhandled exception occurs, Playwright dumps a .zip trace archive to target/playwright-traces/.

You can also record all traces from successful and failing tests by setting Options.Trace.ON to the setTrace configuration call. But be careful when doing so in a project with large number of E2E tests. It will produce large number of traces, which in turn contain screenshots of the app.

2. Try to Run a Diagnostic Trace Experiment

To observe and inspect trace output:

  1. Temporarily introduce an intentional failure into testSearchSingleOwnerRedirect, for example:
    1
    assertEquals("Incorrect Name", ownerPage.getOwnerName());
    
  2. Run the test:
    1
    ./mvnw test -Dtest=FindOwnersE2ETests
    
  3. Check the target/playwright-traces/ directory. You will find a newly generated zip file containing the recorded trace.
  4. Open the Trace Viewer on trace.playwright.dev and upload the .zip file. Alternatively, if you have Node.js toolchain installed, you can also run the Trace Viewer locally:

1
npx playwright show-trace target/playwright-traces/<trace-file-name>.zip
5. Inspect the trace UI: examine the action timeline, the point of assertion failure, and the DOM snapshot at the exact moment the test failed. 6. Revert your deliberate failure so the test suite passes cleanly.

Task 5: DIY - Owner Registration & Pet Creation

In this hands-on task, you will independently design two new Page Objects and write a complete E2E user journey test:

  1. Design AddOwnerPage under src/test/java/org/springframework/samples/petclinic/e2e/pages/AddOwnerPage.java:
    • Represents the form at /owners/new.
    • Encapsulates locators and filling actions for:
      • First Name
      • Last Name
      • Address
      • City
      • Telephone
      • Submit button (Add Owner)
    • Prioritise accessible locators (getByLabel(...), getByRole(...)).
  2. Design AddPetPage under src/test/java/org/springframework/samples/petclinic/e2e/pages/AddPetPage.java:
    • Represents the form at /owners/{ownerId}/pets/new.
    • Encapsulates locators and filling actions for:
      • Name
      • Birth Date (format: YYYY-MM-DD, e.g., 2024-05-15)
      • Type (select dropdown; valid options include cat, dog, lizard, snake, bird, hamster)
      • Submit button (Add Pet)
  3. Implement OwnerRegistrationAndPetE2ETests under src/test/java/org/springframework/samples/petclinic/e2e/:
    • Test name: testRegisterNewOwnerAndAddNewPet
    • Scenario flow:
      1. Navigate to /owners/find and click "Add Owner".
      2. Fill the owner registration form with unique test data (e.g., first name: Kak, last name: Burhan, address: Jl. Buntu 12, city: Ciburhan, telephone: 7501234567) and submit.
      3. Assert that the browser redirects to /owners/{id} displaying the Owner Information heading with the submitted owner information.
      4. Click "Add New Pet".
      5. Fill the pet creation form (e.g., name: Garong, birthdate: 2024-01-01, type: cat) and submit.
      6. Assert that the browser redirects back to the Owner Information page.
      7. Assert that the newly created pet is visible in the "Pets and Visits" table with the correct pet type and birthdate.
      8. Navigate back to /owners/find, search by the new owner's last name (Burhan), and verify that the owner and pet record are successfully loaded from the database.

Run your new E2E test and verify it passes:

1
./mvnw test -Dtest=OwnerRegistrationAndPetE2ETests

Deliverables

At the end of this exercise, commit and push your changes to your fork on GitLab CSUI under the task/3-mutation-and-e2e branch:

  1. A Markdown file named EXERCISE_3_REPORT.md located in the root of your repository (see template below).
  2. Updated fork of Spring Petclinic with your changes, including the new test cases.
  3. Include at least one trace sample (e.g., a trace_1.zip file) that can be viewed in Playwright Trace Viewer.

The due date for this exercise is: Tuesday, 8 November 2026, 23:55 UTC+7.

Submit the URL of your forked repository and branch to the designated submission slot on SCELE before the deadline.

GenAI Usage Policy

This exercise allows GenAI and LLM tools as learning materials and tools. Even so, it is still imperative for you as course participant of SQA and user of GenAI to factually check the responses generated by GenAI.

The use of GenAI does not mean you can entirely delegate your learning process to GenAI. You enrolled in a course to learn and obtain knowledge and skills. Do not make GenAI the one that does the learning, turning you into a "meat proxy" for it.

Allowed Uses

  • Setting up CI/CD pipeline on GitLab CSUI.
  • Generating initial boilerplate skeletons for Page Object classes based on HTML structures.
  • Clarifying Playwright locator APIs and ARIA accessibility roles.
  • Explaining trace analysis and debugging failed assertions.

Prohibited Uses

  • Blindly pasting AI-generated tests without running, understanding, and validating them locally.
  • Generating test execution logs or Trace Viewer screenshots in your report.

Report Template

Use the following Markdown template for EXERCISE_3_REPORT.md:

Note: you can write your report in English or Bahasa Indonesia.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Exercise 3 Report: Mutation Testing with Pitest & E2E Testing with Playwright

- **Name:** <NAME>
- **NPM:** <NPM>
- **GitLab Repository URL:** <URL>

## 1. Mutation Testing Metrics Summary

| Metric | Baseline (Task 2) | After Guided Fix (Task 3) | After DIY Fix (Task 4) |
|---|---|---|---|
| Line Coverage (%) | | | |
| Mutation Coverage (%) | | | |
| Test Strength (%) | | | |
| Total Mutants Generated | | | |
| Total Mutants Killed | | | |

## 2. DIY Mutant Analysis (`Owner`)

- RIPR Analysis:
  - Reachability: <How was the line reached?>
  - Infection: <How did state become corrupt?>
  - Propagation: <Why did or didn't the corrupt state reach observable outputs?>
  - Revealability: <What assertion was missing in the existing tests?>
- Test Implementation:
  <Show the test code snippet added to OwnerTests.java>
- Verification:
  <Attach snippet or screenshot confirming the mutant is KILLED>

## 3. End-to-End (E2E) Testing with Playwright

Based on, at least, one included trace in your forked repository:

1. Attach a screenshot in your report, showing the Trace Viewer timeline of the included trace.
   For example: `![Trace Viewer Snapshot](<path to your screenshot>)`
2. Open the trace using the Trace Viewer. Then, inspect the timeline.
   Once you have inspected the trace, answer the following question:
   "How does a trace timeline will help you as a developer in fixing a failing E2E test case?"

## 4. Interesting / Relevant Findings (Optional)

> Write down your interesting findings here, if any, that not necessarily related to the exercise but still relevant to the SQA as a whole.
> For example, try to run the E2E tests not in headless mode and observe the performance.
> Or try alternative mutation engine called Descartes mentioned in [last year's exercise](../2025/exercise3.md).

GenAI Use Disclosure

Antigravity CLI with Gemini 4 Hydrogen model was used to:

  • Proofread this document.
  • Draft the exercise instructions about POM pattern.
  • Generate the POM pattern code examples based on Spring Petclinic codebase.

We claim no authorship of the POM pattern code examples except the abstract test suite, which based on a prior work made by the teaching team. However, we have verified the generated code, and we have prior experience in implementing POM pattern. Hence, we release the code under CC0 1.0 Universal (public domain). We have reviewed and edited the generated text.

References