Introduction of Cypress A Test Automation Tool – Devstringx

Back to Blog
Banner image for Cypress Blog

Introduction of Cypress A Test Automation Tool – Devstringx

Introduction of Cypress Tool

Cypress is an open-source and free test automation tool, It is mainly used for front-end automation. Cypress helps to achieve the following −

  1. Configure tests
  2. Configure tests
  3. Execute tests
  4. Identify errors (if any)

Selenium and Cypress are compared in terms of their functionalities. In Many ways, Cypress is different in architecture and features.  it resolves some of the issues users face in Selenium.

Cypress is based on JavaScript and executes tests in the browser. It helps to develop the tests which have −

  1. Unit tests
  2. End-to-end tests
  3. Integration tests

Features of Cypress Testing Tool

The important features of Cypress are given below −

  1. Supports Test-Driven development
  2. Efficient debugging with Developer Tools with the generation of stack trace and errors

Structure of A Basic Test

Cypress follows the JavaScript test frameworks like (Mocha, and Jasmine). To create a test in Cypress, we have to follow the below-mentioned framework guidelines −

-Test suite name should be provided within the described function

Basic Test Implementation

The basic test implementation can be done by using the below command –

// test suite name
describe('JavaTpoint Test', function () {// Test case
   it('Scenario 1', function (){
      // test step for URL launching
Test Execution

For execution from the command line, run the command mentioned below −

./node_modules/.bin/cypress run

Here, all the files within the integration folder will get triggered

For execution from the Test Runner, run the command Mentioned below −

./node_modules/.bin/cypress open

Then, click on the spec file that the user wants to trigger for execution.

To trigger execution for a specific file from the command, run the command mentioned below −

cypress run --spec "<spec file path>"

Also Read:- Web Automation Testing Tools

Cypress – Basic Commands

Cypress basic commands are mentioned below –

  • and

It use to create assertions and is an alias. should ().

  • as

This command provides an alias for later usage.

  • blur

It blurs an element in focus.

cy.get('#txt'). type('abc').blur()
  • check

Checks radio buttons or checkboxes and also apply to elements having input tags.

  • children

It basically obtains the sub-elements of an element.

  • clear

Generally, It removes the value from textarea or input.

cy.get('#txt'). type('abc').clear()
  • clearCookie

It removes a particular browser cookie.

  • clearCookies

This command removes the cookies from the browser from an existing domain and subdomain.

  • clearLocalStorage

It removes the local Storage data from the existing domain and subdomain.

//clears all local storagecy. clearLocalStorage ()
  • click

It clicks an element in (DOM).

//click on element with id txtcy.get('#txt').click()
  • contains

It obtains an element having a specific text. The element can have more than the text and still, match.

  • dblclick

It double-clicks an element in DOM

//double clicks element with id txt
  • debug

It fixes a debugger and the log value is returned by the prior command.

//pause to debug at start of command
  • document

It obtains a window. document on the active page.

  • each

It iterates from an array having the property length.

//iterate through individual li
cy.get('li').each(() => {...})
  • end

It ends a command chain.

//obtain null instead of input
  • eq

It is referring to an element at a particular index in an array of elements.

//obtain third td in tr
  • exec

It runs a system command.

cy.exec('npm init')
  • find

It is obtaining the descendant element of particular locators.

//obtain td from tr
  • first

It is obtaining the first element from a group of elements.

//obtain first td in tr
  • get

It is obtaining single or multiple elements by the locator.

//obtain td from tr
  • find

It is obtaining the descendant elements of a particular locator.

//obtain all td from tr in list
  • getCookies

It is obtaining  all the cookies

  • go

It moves forward or backward to the next or previous URL in the history of the browser.

//like clicking back button
//like clicking forward button
  • visit

It launches an URL.

  • next

It obtains the immediate sibling of an element in a group of elements in DOM

//gives the following link in element l.
cy.get('l a:first').next()
  • parent

It obtains the parent element from a group of elements in Document Object Modal.

//get parent of element with class h
  • should

It is used for creating an assertion and is an alias of .and ().

//assert element is visible & enabled
  • wait

Wait for a certain time in milliseconds or for an aliased element prior to moving the following step given below.

  • title

It will obtain the document.title of the active page.

  • log

It will print the messages to the Command Log.

cy.log('Cypress logging ')
  • reload

It is used for page reloading.


Also Read – Tutorial On Katalon Studio an Automation Testing Software Tool

Cypress Assertions

Cypress has more than one type of assertion obtained from various libraries like Mocha, Chai, etc. The two types of assertion types are explicit and implicit.

1) Implicit Assertions

If an assertion is applicable to the object obtained from the parent command in a chain, then that is known as the implicit assertion. The popular implicit assertions include .and/.should.

These commands cannot be used as a standalone. Generally, they are used when the user has to verify multiple checks on a particular object.

// test suite
describe('W3 school', function () {
   it('Scenario 1', function (){
      //  step to launch a URL
        //  validate count of sub-elements and class attribute value
        cy.get('.toc chapters').find('li').should('have.length',5)
        .and('have.class', 'dropdown')
2) Explicit Assertions

An assertion is applicable to an object, it is known as the explicit assertion. The popular explicit assertions include asserting/expecting.

The command for the explicit assertion is mentioned as follows –

// test suite

describe('Tutorialspoint', function () {

// it function to identify test

   it('Scenario 1', function (){

      // step to launch the  URL


                        // identify element


         const t = e.text()

         // assertion expect






Share this post

Back to Blog