GUIDE / automation
Cypress Tutorial for Beginners: Your First E2E Test
Cypress tutorial for beginners covering setup, your first E2E test, selectors, assertions, fixtures, debugging, CI, and stable automation habits.
Cypress tutorial for beginners should not start with twenty configuration switches. It should get you to one trustworthy end to end test, then teach the habits that keep the suite useful after the first green run. Cypress is popular because it gives quick feedback, automatic retries, readable commands, and a browser runner that helps you see what happened. The risk is that beginners can write tests that look clean but depend on unstable selectors, hidden timing, shared data, or UI shortcuts that users never take.
This guide gives you a practical path you can use in a real QA workflow: what to learn first, how to structure the first useful test, what to avoid, and how to decide when the test is good enough for a regression suite. You will see examples, a comparison table, common mistakes, and links to related guides such as cypress best practices, cypress vs playwright 2026, playwright tutorial, selenium vs playwright vs cypress.
Cypress Tutorial for Beginners: The Practical Path
The fastest way to learn is not to memorize every command. The fastest way is to connect each command to a testing decision. Every browser action, request, wait, fixture, assertion, and helper should answer one question: what product behavior are we protecting. When that question is clear, the tool becomes easier to learn because you know why each feature exists.
Start with one stable environment and one behavior that matters. Do not begin by testing the hardest integration in the product. Pick a small flow with a visible result, such as required field validation, successful search, account settings update, or a simple create action. Once that first check is reliable, add data setup, more roles, negative paths, and CI execution.
What Cypress Is Best At
Cypress is strongest when you are testing a browser based user flow in a web application that your team can control. It runs close to the app, gives rich debugging information, and makes it easy to combine UI actions with network inspection. A good Cypress suite protects the flows that matter to users, such as sign in, checkout, settings changes, report generation, and critical form submission. It is not a replacement for unit tests, contract tests, or exploratory testing. It is one layer in the test strategy.
A useful cypress tutorial for beginners does not treat automation as a trophy. It treats automation as a way to make release decisions with better evidence. Before you add another spec, ask what failure would matter, who would act on the result, and whether the test can explain the risk in a way another tester can review.
Project Setup
Install Cypress in the project that owns the web app, not in a random folder that has no access to app scripts. Most teams use npm, pnpm, or yarn, then add scripts for opening the runner and running headless tests in CI. Keep the first setup boring. Use the default folder layout, create one spec, and verify that the app opens at a stable base URL. Once the first test passes locally and in CI, then add fixtures, commands, reporters, and environment specific configuration.
The beginner path is simple, but it must be disciplined: choose one behavior, control the starting state, act like a user or a clear client, and assert the result that proves the behavior. When the test fails, the failure should point to a product issue, a data issue, an environment issue, or a test design issue.
Your First Test Flow
A strong first Cypress test should exercise a real user behavior with a clear pass or fail result. Choose a small flow that does not require complicated data setup. For example, a public login validation test, a search result check, or a contact form validation message. Avoid starting with payment, third party authentication, or file downloads. You are learning Cypress mechanics first: visit a page, find elements, act like a user, and assert visible outcomes.
For selectors, prefer names and attributes that survive design changes. For data, prefer records owned by the test. For assertions, prefer outcomes that users or systems care about. These three decisions prevent many expensive rewrites later.
Selectors and Assertions
Selectors decide how fragile your Cypress suite will be. Prefer data attributes that describe testing intent, such as data-testid or data-cy. Avoid selectors based on CSS classes created for styling, indexes inside repeated lists, or exact layout structure. Assertions should describe user visible behavior: page title, success message, row created, button disabled, URL changed, request returned, or data persisted. The better the assertion, the more useful the failure.
Do not measure success by the number of tests added in the first week. Measure it by the number of meaningful failures the suite can explain. A small suite with ten trusted checks is more valuable than a large suite that everyone reruns until it passes.
Debugging Cypress Tests
The Cypress runner gives a command log, snapshots, screenshots, videos, console output, and network details. Use those tools before guessing. When a test fails, ask whether the product failed, the selector failed, the data changed, the app was still loading, or the assertion was too vague. Cypress retries commands and assertions, but it does not fix poor state control. Debugging skill is part of automation skill, not a separate phase.
When a test becomes flaky, slow down and classify the failure. If the app is broken, report a defect. If the data is shared, isolate it. If the locator is fragile, improve the app testability. If the environment is overloaded, fix infrastructure before blaming the tool.
Common Mistakes in Cypress Tests
Beginners often add arbitrary waits, reuse one shared account, test implementation details, or write one long test that checks ten behaviors. Another common mistake is using Cypress only as a click recorder, which creates scripts that follow the UI but do not verify meaningful outcomes. Avoid cy.wait(5000) as a timing strategy. Wait for observable state, route aliases, visible elements, or backend responses that represent readiness.
Review automation like production code, but judge it by testing value. The code should be readable, the coverage should be intentional, and the maintenance cost should be visible. A clever helper that hides the business behavior is usually a bad trade.
Maintaining a Cypress Suite
A Cypress suite becomes valuable when it survives product change. Keep tests focused, name specs by feature, share setup through commands only when the abstraction is obvious, and delete low value checks that fail often without catching product risk. Review failures weekly. If the same test fails for three unrelated reasons, improve its setup or remove it from the critical path.
Teams improve fastest when they keep examples close to real workflows. Use login, search, checkout, profile updates, permission checks, imports, exports, and notifications. These flows reveal timing, state, and data problems better than toy examples.
Example You Can Adapt
The example below is intentionally small. Its job is to show the shape of a useful check: setup, action, assertion, and a readable failure. Adapt the selector style, base URL, and assertion to your application. Do not copy the example blindly if your app exposes better test hooks or a more direct setup path.
npm install --save-dev cypress
npx cypress open
// cypress/e2e/login-validation.cy.js
describe('login validation', () => {
it('shows a required password message', () => {
cy.visit('/login');
cy.get('[data-cy=email]').type('qa.user@example.com');
cy.get('[data-cy=submit]').click();
cy.contains('Password is required').should('be.visible');
});
});
Comparison Table
| Cypress concept | Beginner use | Quality habit |
|---|---|---|
| cy.visit | Open a route or page | Use a configured baseUrl so environments stay consistent |
| cy.get | Find elements | Prefer data attributes over CSS styling classes |
| cy.contains | Find visible text | Use for user facing labels, not large ambiguous areas |
| cy.intercept | Observe or stub network calls | Alias important requests instead of sleeping |
| cy.fixture | Load stable test data | Keep fixture data small and business readable |
| Custom commands | Reuse repeated setup | Do not hide important assertions inside helpers |
Common Mistakes
Mistake 1: Testing the Tool Instead of the Product
Beginners sometimes write tests that prove they can click buttons, but not that the product works. A script that opens a page, clicks submit, and ends without a meaningful assertion is not useful regression coverage. Every test should have a reason to exist. The reason should be visible in the test name and the assertion.
Mistake 2: Depending on Shared Mutable Data
Shared accounts, shared carts, shared reports, and shared records create failures that have nothing to do with product quality. If another test or tester can change the state you depend on, your result is not trustworthy. Prefer unique data, setup APIs, fixtures, or cleanup routines that make the starting state clear.
Mistake 3: Hiding Timing Problems With Sleeps
Fixed sleeps are tempting because they make a failing test pass on your machine. They are also one of the fastest ways to create a slow and flaky suite. Wait for the thing that matters: visible message, enabled control, changed URL, completed request, available frame, or persisted record.
Mistake 4: Over Abstracting Too Early
A page object, command, fixture, or helper should remove real duplication and improve readability. If the abstraction hides what the test is doing, it makes review harder. Write the first few tests plainly. Extract patterns only after the repeated shape is obvious.
Mistake 5: Ignoring Negative and Boundary Behavior
Happy path automation is useful, but many serious defects live in invalid input, expired sessions, permission boundaries, duplicate submissions, slow responses, and edge values. Add negative checks where the risk is real. Do not add random bad data just to increase the test count.
Mistake 6: Treating CI Failures as Noise
A CI failure is feedback. If the product failed, the test did its job. If the test failed because of timing, data, or environment, the suite needs maintenance. Rerunning without diagnosis teaches the team to ignore automation. Classify failures and fix the cause.
How to Review Your Work
Use this checklist before calling the test complete:
- The test name describes a product behavior.
- The setup creates or verifies the required state.
- Selectors are stable and understandable.
- Waits are based on meaningful conditions.
- Assertions prove user visible or system visible outcomes.
- Test data is isolated from other tests.
- Failure output would help someone debug without guessing.
- The test belongs in the selected suite: smoke, regression, feature, or exploratory support.
If you are building a larger automation path, connect this guide with Page Object Model, how to fix flaky tests, and CI/CD for test automation with GitHub Actions. Those guides help turn a single useful test into a suite that can run during real delivery.
After you write your first spec, try a short automation challenge in QABattle battles. The fastest way to improve is to compare your script against a small app with real validation and state changes.
Practice Plan
Day one: install the tool, open the application, and write one test for a simple validation behavior. Keep the code plain. Do not add custom reporters or abstractions yet.
Day two: add one positive path and one negative path. Review selectors and waits. Replace any fixed sleep with a condition based wait. Make test data explicit.
Day three: run the tests headless and collect failure evidence. Add screenshots, traces, logs, or reports only where they help diagnosis. Document how to run the suite locally.
Day four: move setup out of repeated UI steps where appropriate. Use an API, fixture, factory, or helper only when it makes the test faster and clearer.
Day five: review the suite with another tester or developer. Remove weak assertions, split tests that cover too many behaviors, and add one regression case for a defect that the team genuinely wants to prevent.
Final Checklist
cypress tutorial for beginners should leave you with more than a passing demo. You should understand the testing decisions behind the code. Choose a behavior that matters, control the state, use stable locators, wait for meaningful readiness, assert the outcome, and keep the suite small until it earns trust. That pattern applies whether you use Cypress, Selenium, WebdriverIO, Playwright, or another tool. The syntax changes, but the testing discipline stays the same.
Advanced Practice Notes
Test Data Strategy for Cypress Beginners
Cypress beginners often spend too much time clicking through setup screens. That makes tests slow and fragile. A better approach is to decide which part of the flow you are actually testing. If the test verifies login validation, create the required account before the test starts. If the test verifies checkout totals, create the cart state directly when the application supports it. Use the UI for the behavior under test, and use faster setup paths for everything else.
A practical Cypress data strategy has three levels. The first level is static fixture data for simple forms, such as names, email patterns, or product examples. The second level is API setup through cy.request, which is useful for creating users, orders, and records. The third level is database or service level setup, which should be wrapped carefully and used only when the team owns that access. Each level should leave the test easy to understand.
Avoid data that lives forever and changes silently. If every test uses buyer@example.com, one password change can break the suite. Generate unique emails when possible, such as qa.buyer plus a timestamp. If cleanup is available, delete records after the test. If cleanup is not safe, mark generated records clearly so test data does not pollute manual review.
Cypress Assertions That Catch Real Bugs
The easiest assertion is also often the weakest assertion. Checking that a button exists after a page loads does not prove the workflow works. Strong Cypress assertions connect to outcomes: the cart count increases, the confirmation number appears, the invalid password message is visible, the API returned the expected status, or the created record appears in a list.
Use chained assertions when they make the expected state clearer. For example, assert that a submit button is disabled before required fields are entered, then enabled after valid input. That checks validation behavior, not just page structure. For forms, assert both the visible message and the fact that submission did not continue. For create actions, assert the success message and the durable result, such as a row in the table or a follow up API response.
Be careful with negative assertions. A test that says an error message should not exist can pass before the app finishes loading. Prefer a positive readiness signal first, then a negative assertion if needed. For example, wait for the dashboard heading, then confirm that the error banner is not visible.
Running Cypress in CI
Local success is only the first checkpoint. A useful Cypress suite must run in CI with the same base URL pattern, browser version expectations, and environment variables. Keep CI commands explicit. Run a small smoke suite on every pull request, then run broader regression on schedule or before release. This keeps feedback fast without pretending every test must run on every commit.
Capture screenshots and videos for failed CI runs. They are not decorations. They shorten failure review and help the team decide whether the failure is product, test, data, or environment related. If the same test fails often in CI but not locally, compare machine resources, browser version, viewport, network access, and data isolation.
When Not to Use Cypress
Cypress is excellent for many browser flows, but it should not carry every testing responsibility. Do not use Cypress for load testing. Do not use it as the only API contract test layer. Do not automate visual judgment that requires human review unless you have a visual testing tool. Do not use it to test third party systems beyond the integration behavior your app controls.
A healthy Cypress suite sits beside unit tests, API tests, manual exploratory testing, accessibility checks, and performance checks. The suite should be small enough to maintain and important enough that failures stop the team. That balance is what turns a beginner Cypress project into a serious regression asset.
Release Readiness Checklist for Cypress Suites
Before a Cypress test becomes release blocking, run it several times locally and in CI. Look for three qualities: it starts from a known state, it fails for a clear reason, and it finishes fast enough to belong in the chosen suite. A test that sometimes depends on old browser storage, stale backend records, or another test execution should stay out of smoke coverage until the state problem is solved.
Review the spec names as if a release manager will read them during a failed build. Names such as validates required password or creates draft invoice are useful. Names such as test case one or user flow are not. Clear names reduce panic during failures because the team can quickly understand what risk is blocked.
Finally, decide what evidence Cypress should save. Screenshots are useful for layout and message failures. Videos help for multi step flows. Network aliases help when the UI depends on API timing. Console logs help when the app throws client side errors. Save enough evidence to debug, but do not bury the team under artifacts nobody opens.
FAQ
Questions testers ask
Is Cypress good for beginners?
Yes. Cypress is beginner friendly because installation is simple, the test runner is visual, and commands automatically retry. Beginners still need to learn selectors, assertions, test data control, and how the browser event loop affects testing, but the first useful test is usually faster than with older browser tools.
What should I learn before Cypress?
You should know basic JavaScript, HTML selectors, the browser developer tools, and the difference between user behavior and implementation detail. You do not need advanced frontend knowledge to start, but you will write better Cypress tests if you understand how forms, network calls, and page state work.
Can Cypress test APIs?
Cypress can make HTTP requests with cy.request and can stub or inspect network calls with cy.intercept. It is not a full API testing platform by itself, but it is very useful for setting up data, checking backend responses that support an E2E flow, and reducing dependence on the UI for repetitive setup.
Is Cypress better than Selenium?
Cypress is usually easier for modern web app E2E testing, especially for JavaScript teams. Selenium is broader because it supports more languages and remote browser grids. The better choice depends on browser coverage, team skills, application architecture, and whether you need cross language or large scale grid execution.
How many Cypress tests should a beginner write first?
Start with three to five high value flows: sign in, one critical create action, one validation path, one navigation path, and one regression for a past bug. That gives you enough practice with selectors, assertions, setup, and debugging without creating a large suite before you understand maintenance costs.
RELATED GUIDES
Continue the route
Cypress Best Practices
Cypress best practices for stable E2E tests: selectors, waits, isolation, Page Objects, network stubs, CI tips, and common mistakes to avoid in real projects.
Cypress vs Playwright 2026: Which Tool Should You Choose?
Cypress vs Playwright 2026 comparison for QA teams choosing E2E tools, covering speed, browsers, debugging, API testing, CI, and overall team fit.
Playwright Tutorial: End-to-End Testing from Scratch
Playwright tutorial for beginners: install, write your first test, TypeScript setup, codegen, fixtures, API testing, debugging, and CI tips in one guide.
Selenium vs Playwright vs Cypress in 2026
Compare Selenium vs Playwright vs Cypress in 2026 for speed, browsers, CI, flakiness, ecosystem, and which web automation framework beginners should choose.