Introduction to Cypress Test Runner
Writing Your First Cypress Test: A Beginner’s Guide
Cypress is a powerful tool for testing web applications.
If you're a developer or QA tester looking to write fast and reliable UI tests, Cypress is a great place to start.
In this post, you'll learn how to write your first Cypress test step by step.
π§° What is Cypress?
Cypress is an open-source front-end testing tool built for the modern web.
It lets you write tests in JavaScript to verify how your website behaves in the browser.
You can use it for:
-
End-to-End (E2E) testing
-
Integration testing
-
Unit testing (limited)
π ️ Step 1: Set Up Cypress
If you haven’t already, create a new project:
To open the Cypress Test Runner:
It will create a cypress/ folder with example tests inside.
π Step 2: Create Your First Test File
Create a file inside:
And write this code:
π Step 3: Understanding the Test
Let’s break it down:
-
describe()— Groups related tests -
it()— Defines an individual test case -
cy.visit()— Opens the target web page -
cy.contains()— Finds an element with matching text -
cy.url()— Checks the current URL -
cy.get()— Selects an input field -
.type()— Types into the field -
.should()— Asserts expected behavior
This simple test:
✅ Opens a demo page
✅ Clicks on a link
✅ Types an email
✅ Checks if it worked
π§ͺ Step 4: Run the Test
Once you open Cypress with:
You’ll see your test file listed in the UI. Click it to run.
Cypress opens a browser and runs your test visually — step by step!
π‘ Tips for Beginners
-
Use browser DevTools to inspect elements before writing selectors
-
Cypress auto-reloads when you update your tests
-
Use
.debug()or.pause()to slow things down and troubleshoot -
Prefer
data-*attributes (likedata-cy="login-btn") for reliable selectors
π Final Thoughts
Cypress makes testing fast, fun, and easy.
Your first test is just the beginning. From here, you can:
-
Test login forms
-
Validate shopping carts
-
Automate complex user flows
-
Run tests in CI/CD pipelines
The more you test, the more confident you'll feel shipping your code.
Comments
Post a Comment