Writing Your First Test in Cypress

 ✅ Writing Your First Test in Cypress

Cypress is a modern JavaScript-based testing framework used for end-to-end testing of web applications. It’s known for being easy to set up and powerful for UI testing.


πŸ›  Step 1: Install Cypress

If you haven’t already, set up a Node.js project and install Cypress:


bash

Copy

Edit

npm init -y

npm install cypress --save-dev

To open Cypress for the first time:


bash

Copy

Edit

npx cypress open

This will open the Cypress Test Runner and generate a cypress folder with some sample tests.


πŸ“ Step 2: Create a New Test File

Go to the folder:

cypress/e2e (or cypress/integration in older versions)


Create a new file:

first_test.cy.js


πŸ§ͺ Step 3: Write Your First Cypress Test

javascript

Copy

Edit

describe('My First Test', () => {

  it('Visits the example website and checks content', () => {

    cy.visit('https://example.cypress.io')          // Visit a webpage

    cy.contains('type').click()                     // Click on a button or link

    cy.url().should('include', '/commands/actions') // Assert URL contains text

    cy.get('.action-email')                         // Get an input field

      .type('test@example.com')                     // Type into it

      .should('have.value', 'test@example.com')     // Assert value

  })

})

▶️ Step 4: Run the Test

Run Cypress: npx cypress open


Click your test file (first_test.cy.js) in the Cypress Test Runner


Watch the test execute in the Cypress GUI


🧠 What’s Happening?

describe() defines a test suite


it() defines a single test case


cy.visit() opens a web page


cy.contains() finds and clicks an element


cy.url().should() verifies the page URL


cy.get().type().should() interacts with input fields and asserts results


πŸ“Œ Tip:

Use Cypress Studio (built into Cypress) to record actions interactively, and turn them into test code — great for beginners!

Learn Testing Tools Training in Hyderabad

Read More

Top 10 Software Testing Tools in 2025

How to Install and Run Selenium

Bugzilla vs Jira: Which Is More Efficient?

Sauce Labs vs Lambda Test

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

How to Install and Set Up Selenium in Python (Step-by-Step)

Feeling Stuck in Manual Testing? Here’s Why You Should Learn Automation Testing

A Beginner's Guide to ETL Testing: What You Need to Know