Skip to content
Agrim Intelligence

Insights · Guide

How to create test cases: check for duplicates first

By Agrim · Published November 20, 2026 · 6-minute read

In short

How to create test cases: check existing coverage for duplicates, combinations and siblings, and keep selectors in read-only page object locators.

This guide shows how to create test cases and submit them to a lead for approval. Check existing coverage for duplicates, combinations and siblings first, then keep selectors in the read-only locator at the top of each page object, reused across the file.

Check for duplicates before you create test cases

To create test cases without adding duplicate tests, start creating automated test cases with a duplicate check, not a new file. The check can also find combinations and siblings, so a new test could be avoided by adding steps to an existing test or placing the test in an existing file.

Otter's test creation workflow begins by searching existing scenario and action files for primary feature keywords. It then scores overlap as shared steps divided by the maximum of the existing and new step counts, multiplied by 100. In our view, a score like this gives a team a figure to apply to each new test. The workflow works through three scores:

  • 5 shared steps against step counts of 5 and 6 is 5/6, or 83%. The workflow's recommendation is to extend the existing scenario.

  • 4 shared steps against counts of 6 and 6 is 4/6, or 67%. The recommendation is to extract the shared browse and add steps into a helper and create a new scenario.

  • 0 shared steps against counts of 4 and 6 is 0%. The recommendation is to create a new scenario.

When you extend a scenario, the same workflow prohibits duplicating the existing scenario's setup in a new file, creating "v2" scenarios, or altering happy paths without approval. That last rule, in our view, keeps people in charge of any change to a happy path that already exists. In our view, the next question is where the test's selectors live.

Isolate selectors into read-only locators at the top of each page object

Once the duplicate check is settled, selectors are updated in one place when creating page object test cases: the read-only locators at the top of the page object. Playwright's documentation describes page objects as modelling the web application UI to create a high-level API, with element selectors centralised in one place. In Playwright, page elements are isolated as readonly locator properties declared on the class. Selenium's guidance describes a page object as "an object-oriented class that serves as an interface to a page", so tests do not change when the underlying UI changes.

Codeception instructs teams not to hard-code complex CSS or XPath locators in test cases and to move them into page object classes. Slack's engineering team adds a custom data-qa attribute to elements it needs to select for testing, instead of relying on product-driven class names or element ids.

A reviewer, in our view, can check the selectors in one block and then read the steps below it as plain actions. A selector that appears anywhere else in the file is, in our view, a reason to send the test back.

A flat editorial illustration in white, gray and black with one cyan accent, for a practitioner guide article.

Keep scenario-driven tests to simple interaction commands

In our view, the guidance below points to a test body that calls page object methods and keeps complex logic out of the test.

Codeception recommends that scenario-driven tests contain only simple interaction commands, not complex embedded logic. Slack's component design dictates that methods inside a component should modify only the specific piece of UI they were designed for. Martin Fowler advises that page objects should provide access to page state rather than making assertions themselves, and that it is up to test clients to carry out the assertion logic.

Slack observed a 60% decrease in test flakiness after migrating its end-to-end tests to its UI Abstraction framework. The figure compares test results from before and after that migration, so it describes Slack's own move and not a guaranteed outcome. A short test made of named method calls and one assertion is, in our view, a shape a lead can review quickly.

Page objects have real objections that narrow our conclusion

Cypress argues that page objects take time away from application development and are hard to maintain. It adds that they introduce a separate test state distinct from internal application state, which complicates comprehension and failure triage. It also says they make tests slow because they force tests to go through the application user interface.

Fowler's page cites a study in which page objects needed slightly more time to update for the first test case after an upgrade, but were faster for subsequent cases. That result, in our view, supports single-source locators where many tests share a page, and it does not answer the Cypress points about state and speed. The conclusion, in our view, narrows rather than reverses: keep one place for selectors, but do not assume every test belongs on the UI path.

A page inspector defines selectors and locators

A page inspector scans a website's HTML, reads its source, and defines selectors and locators. Each page object has a read-only locator at the top that is reused across the file, so selector changes need updating in only one place.

In our view, this puts the single-source principle that Playwright and Codeception describe into the moment a page object is created, instead of leaving it to each author's discipline. It does not, in our view, settle the Cypress objection about separate test state and slow UI paths, which depends on how a team's tests are built and not on where the locators sit.

When the page object part of this workflow may not fit

Cypress suggests dispatching actions directly to internal application logic when tests run alongside application code; in our view, a team in that position can skip the page object part of this workflow. Fowler's page also notes that architectural patterns that move logic out of UI elements reduce the need for UI testing and page objects. In our view, those are the setups where the Cypress concern about separate test state may apply.

The overlap rule also has an exit: in the Otter example with 0% overlap, the recommendation is to create a new scenario. For a lead deciding what to approve, three checks follow from the test case design steps above:

  • Is the duplicate check shown, with its overlap score against existing scenarios?

  • Do selectors appear only in the read-only locator block at the top of the page object?

  • Is the test body limited to page object method calls and a visible assertion?

In our view, for automated test case approval, a submission that passes all three needs a short review, and one that fails any of them needs a person to decide whether it should exist at all.

Frequently asked questions

How do you create test cases without adding duplicate tests?

You start by searching existing scenario and action files for primary feature keywords, as in Otter's workflow. The process scores overlap as shared steps divided by the maximum step count, multiplied by 100. In Otter's worked examples, 83% overlap leads to extending the existing scenario, 67% to extracting shared steps into a helper before creating a new scenario, and 0% to creating a new scenario.

How should automated test cases be structured for fast human approval?

Codeception recommends that scenario-driven tests contain only simple interaction commands rather than complex embedded logic. Martin Fowler advises that page objects provide access to page state rather than making assertions themselves, leaving assertion logic to test clients. In our view, limiting the test body to named page object method calls and one assertion is a shape a lead can review quickly.

Where should selectors be updated when creating page object test cases?

With a read-only locator at the top of the page object, reused across the file, selector changes need updating in only one place. Playwright isolates page elements as readonly locator properties declared on the class, while Codeception instructs teams not to hard-code complex CSS or XPath locators in test cases and to move them into page object classes. Selenium's guidance says that when the UI changes, only the code within the page object needs to change.

Sources

Bring us one process you would like to hand to AI. We will show you how it would be checked, and who would sign it off.