October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

Cypress Anti-Patterns to Avoid (and What to Do Instead)

Fix fragile Cypress tests by removing hidden dependencies, styling-based selectors, arbitrary waits, uncontrolled external dependencies, and other common anti-patterns.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a Cypress test passes only after another test, breaks when CSS changes, or relies on a long sleep to settle down, it may be hiding a fragile pattern. The fixes are usually to make setup explicit, select elements by stable test attributes, and wait for the condition that matters—not a guessed amount of time. Cypress calls some practices anti-patterns and presents others as best practices; the distinction matters because a recommendation is guidance, not proof of what caused a particular failure.

1. Making one test depend on another

Cypress’s guidance is direct: “Tests should always be able to be run independently from one another and still pass.” A test that needs a previous test to create a user, leave a page open, or set browser state can fail when run alone, reordered, or when the prerequisite test is skipped. Cypress suggests trying a test with .only() to expose hidden dependencies. Cypress: Test Isolation

Give each test its own deliberate prerequisites. Put genuinely shared setup in hooks or programmatic helpers, but do not make one test responsible for another test’s state.

  • Run a suspect test alone with it.only() or describe.only(), then remove the focus before committing.
  • Run tests in a different order or individually to reveal assumptions about prior browser state.
  • Set up the user, records, or application state needed by each test through controlled setup rather than relying on a previous UI flow.

2. Disabling test isolation as a blanket speed fix

For end-to-end tests, Cypress enables testIsolation: true by default. Before each test, it resets the page to about:blank, cookies across domains, localStorage, and sessionStorage. It does not clear IndexedDB or every other browser storage mechanism. Component tests reset the rendered component and the listed cookie and storage categories; Cypress does not support configuring test isolation for component testing. See Cypress’s isolation details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Setting testIsolation: false for an end-to-end suite or describe block can retain browser state and may improve performance in a particular case, but it also allows tests to affect one another. Treat it as a scoped trade-off, not a general optimization. Before relying on it, verify that tests still pass independently and that each test has explicit setup. Cypress documents this configuration and the related cy.session() behavior at Test Isolation.

With isolation enabled, cy.session() can set up or restore a session, but a test that needs an application page should visit the app after the session setup or restoration. Retaining a session is not the same as retaining a page.

3. Selecting elements through styling or incidental structure

A selector such as .blue-button is coupled to a style choice; a selector based on a tag or a changing DOM structure can be coupled to implementation details. Those selectors may keep working until an unrelated redesign breaks the test. Cypress recommends purpose-built data-* attributes for test targeting, for example:

<button data-cy="submit">Submit</button>
cy.get('[data-cy="submit"]').click()

Use a selector that reflects the test’s intent. A purpose-built test attribute is often durable for locating an element. Text or semantic attributes can be appropriate when the behavior being tested is specifically about user-visible text or HTML meaning. Cypress’s selector examples and recommendations are in Best Practices.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Using fixed waits to guess when something is ready

cy.wait(3000) pauses for three seconds whether the application is ready immediately or still loading afterward. It adds time without establishing that the required condition is true. Cypress says, “You almost never need to wait for an arbitrary period of time. There are always better ways to express this in Cypress.” Cypress: cy.wait()

Wait for a UI condition

Use a Cypress query and assertion. Cypress retries the assertion until it passes or times out, so the test describes what must be true:

cy.get('[data-cy="results"]').should('be.visible')

Wait for a specific request

When a test needs to synchronize with a particular network request, intercept it, assign an alias, and wait for that alias:

cy.intercept('GET', '/api/products').as('getProducts')
cy.visit('/products')
cy.wait('@getProducts')
cy.get('[data-cy="product-list"]').should('be.visible')

Adapt the route and assertion to the application. The alias synchronizes the test with the request; the assertion checks the UI result the user cares about. Cypress’s best-practices guidance covers waiting on UI state and network requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not add sleeps after commands that already signal completion

cy.visit() resolves when the page’s load event fires, and cy.request() resolves when it receives a response. An extra fixed delay after either command is generally unnecessary; wait for a specific subsequent UI condition if the test needs one. Cypress: cy.visit() · Cypress: cy.request()

Make CI wait for server readiness

Starting cypress run at the same time as the application server does not guarantee that the server is ready before the tests begin. Use a readiness check or a CI action that waits for the server instead of adding a guessed shell sleep. Cypress: Continuous Integration

5. Logging in through the UI in every test

Repeating the full login flow can add unnecessary work and couple a test to authentication UI when the behavior under test is elsewhere. Cypress recommends programmatic login where appropriate and deliberate control of application state. Choose a setup approach that fits the application’s authentication model; no single backend-specific recipe applies to every project. Cypress discusses this in Best Practices.

Keep UI login coverage where login behavior itself is under test. For other tests, set up authentication programmatically when the application and test environment support it, then verify the behavior the test is meant to cover.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

6. Depending on third-party websites you do not control

A test that visits or interacts with an uncontrolled external site depends on systems, content, and behavior outside your application. Cypress recommends avoiding that dependency; where appropriate, use the third party’s API through cy.request() instead. Keep external integrations at a boundary you can control or stub, and reserve direct third-party interaction for cases where it is genuinely the subject of the test. This is Cypress guidance, not a diagnosis that every external request is the cause of a failure. Cypress: Best Practices

7. Reusing page objects in ways that hide intent

Cypress lists sharing page objects among its discouraged patterns and recommends organizing tests around features and user flows rather than mirroring page structure. The concern is not that every abstraction is harmful; it is that a shared layer can obscure what a test does or where its state comes from. Prefer helpers that make repeated setup clearer, and keep the important actions and assertions easy to see in the test. Cypress: Best Practices

8. Writing end-to-end tests with only one assertion—or unrelated assertions

Cypress identifies a “single assertion end-to-end only” approach as an anti-pattern. A user flow can reasonably check several related outcomes, such as a confirmation message and the resulting item in a list. Do not interpret that guidance as a reason to combine unrelated behaviors into one long scenario. Keep assertions tied to the behavior under test so a failure remains understandable. Cypress: Best Practices

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

9. Hard-coding secrets in test files

Do not put secrets in test source code or expose sensitive values to the browser context. Use a secret-handling mechanism appropriate to the development and CI environment, and limit where sensitive values are available. A test-only environment does not make a committed or browser-exposed secret safe. Cypress explicitly warns against hard-coding secrets in its best-practices guidance.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

10. Repeating full URLs instead of configuring baseUrl

Cypress identifies using cy.visit() without a configured baseUrl as an anti-pattern. Configure the application’s base URL for the environment, then use relative paths such as cy.visit('/login'). This avoids repeating the host in tests and makes it easier to switch environments. Cypress notes that configuration can also avoid an initial reload as the runner moves from its startup URL to the application URL. See Best Practices and Configuration.

A practical way to investigate a flaky Cypress test

  1. Run it alone. If it fails without its neighbors, inspect setup and hidden state dependencies.
  2. Remove timing guesses. Replace fixed waits with an assertion about the UI or a wait for the specific aliased request.
  3. Check the selector. If it encodes a CSS class or incidental structure, use a stable test attribute where appropriate.
  4. Check external dependencies. Identify whether the test relies on a site, service, or server whose readiness or behavior is outside the test’s control.
  5. Inspect isolation settings. If state is retained, verify that the suite needs it and that each test remains understandable and independent.

These checks identify plausible failure modes, not guaranteed causes. The right fix depends on which condition the failing test assumes and whether that condition is controlled.

Or skip the browser setup

If a test or workflow needs a clean screenshot rather than an interactive Cypress assertion, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. Its documented screenshot handling accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

For example, this cURL request captures a page as WebP:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Sign up for 1,000 free screenshots a month, with no card required.

Learn Cypress from its official examples

Cypress offers free official courses and examples through Real World Testing with Cypress.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.