100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Testing

Cypress Best Practices

A practical guide to writing Cypress tests that are fast, resilient to UI changes, and free of the flakiness that erodes trust in a test suite.

Practical CypressIntermediate9 min readJul 10, 2026
Analogies

Writing Reliable Cypress Tests

Cypress tests fail for two very different reasons: the application genuinely broke, or the test itself is poorly written and reports a false negative. Best practices exist to eliminate the second category so that every red run in CI actually means something is wrong with the product. The discipline is less about learning new commands and more about consistently applying a small set of rules around selectors, waiting, and test isolation across an entire suite.

🏏

Cricket analogy: Just as a third umpire only overturns a decision when there is conclusive replay evidence, a good test suite should only turn red when there is conclusive proof the app broke, not because the test itself mistimed a DRS-style check.

Selecting Elements Robustly

Cypress recommends targeting elements with dedicated test attributes such as data-cy, data-test, or data-testid rather than CSS classes, tag names, or text content. Classes and styles change frequently as designers iterate on the UI, and text content changes with copy edits or localization, both of which break tests that have nothing to do with actual functional regressions. A data-cy attribute is a contract between the test suite and the markup that survives refactors of styling and wording alike.

🏏

Cricket analogy: A team that tags a fielder by shirt number rather than by 'the guy near point' can reposition players for different formations without ever losing track of who is who, just as data-cy attributes survive layout changes that would break a CSS-class selector.

Eliminating Flakiness with Retry-ability

Cypress commands like cy.get and cy.contains automatically retry until an element exists and satisfies the assertion chained to it, or until the default 4-second timeout expires. This retry-ability means you almost never need cy.wait(3000)-style arbitrary sleeps; instead you assert on the condition you actually care about, such as an element being visible or containing specific text, and let Cypress poll for it. Arbitrary waits either fail intermittently on slow CI runners or waste time on fast ones, whereas condition-based waiting adapts automatically to real network and rendering latency.

🏏

Cricket analogy: A fielder who keeps his eye on the ball and adjusts his position continuously until the catch is safe is far more reliable than one who commits to a fixed spot after a set count, just as Cypress's retry loop adapts rather than committing to a fixed sleep.

javascript
// Bad: brittle selector and arbitrary wait
cy.get('.btn-primary').click();
cy.wait(3000);
cy.get('.success-msg').should('contain', 'Order placed');

// Good: stable selector, network-aware wait, retry-ability
cy.intercept('POST', '/api/orders').as('placeOrder');
cy.get('[data-cy=checkout-submit]').click();
cy.wait('@placeOrder').its('response.statusCode').should('eq', 201);
cy.get('[data-cy=order-confirmation]').should('contain', 'Order placed');

Avoid cy.wait(<number>) in test code except as a last-resort debugging aid. It couples your test's timing to the current speed of your CI runner, causing tests that pass locally to flake under load. Prefer cy.intercept aliases (cy.wait('@alias')) or assertions that retry automatically.

Structuring Suites for Maintainability

As a suite grows past a handful of specs, repeated interaction sequences such as logging in, adding an item to a cart, or filling a multi-step form should be extracted into custom commands registered via Cypress.Commands.add. This keeps individual test files focused on the behavior being verified rather than on incidental setup steps, and it means a change to the login flow only requires updating one command instead of every spec file that logs in. Custom commands should still use the same stable data-cy selectors internally so the abstraction doesn't hide brittleness, it just centralizes it in one maintainable place.

🏏

Cricket analogy: A team that drills a specific fielding routine like the relay throw from the boundary so thoroughly that every player executes it identically is far more efficient than each player improvising their own version, just as a custom command standardizes a repeated interaction like login.

Cypress's cy.session() command caches authentication state (cookies, localStorage) across tests within a run, so a custom cy.login() command backed by cy.session only performs the real login once and restores the session instantly for subsequent tests, dramatically speeding up suites that need an authenticated user in every spec.

  • Prefer dedicated data-cy/data-testid attributes over CSS classes or text content for element selection.
  • Lean on Cypress's built-in retry-ability instead of cy.wait(<number>) to avoid flaky, timing-dependent tests.
  • Use cy.intercept with aliases to wait on real network responses rather than guessing durations.
  • Extract repeated interaction sequences into custom commands via Cypress.Commands.add.
  • Use cy.session() to cache login state and speed up suites that need authentication in every test.
  • Keep each test independent by resetting application state (via API calls or seed scripts) rather than depending on execution order.
  • Treat every flaky test as a bug to fix immediately, not something to retry until it passes.

Practice what you learned

Was this page helpful?

Topics covered

#Testing#CypressStudyNotes#TestingQA#CypressBestPractices#Cypress#Writing#Reliable#Tests#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse