Cypress Tutorial: A Beginner’s Guide

Introduction to Cypress

Cypress is one of the most popular and commonly used automation tools available out there. The open-source and free tool is written in JavaScript and comes with MIT License. Cypress currently has more than 19K Stars On the Github platform. The automation tool, Cypress is also used by reputed organizations that include DHL and NASA. The Cypress End To End test makes it incredibly easy for users to debug and write.

Cypress is also equipped with a visual interface along with the test script runner. The visual interface can be used to tell which commands and what tests are currently running. In addition, you will be able to determine the failure and passed tests and commands with the visual interface in Cypress. The visual interface also offers several other excellent functionalities and some of them are as follows.

The Visual Interface

The visual interface in Cypress makes it really easy for users to test different types of highly interactive applications. It also allows us to perform several tests like DOM manipulation, submitting forms, writing/reading data from or into fields, and redirecting a separate page without making any direct changes to the code.

It is important to note that the automation tool, Cypress is actually built and optimized as a local development tool. Several developers who used Cypress for some time were encouraged to use the tool for the entire process. This is mainly because Cypress offers a platform that will help users quickly debug and maintain their code with the utmost ease. Now, let us take a quick look into the basics of the Cypress tutorial.

The Basics Of Cypress Tutorial

Introduction And Architecture

Cypress can be defined as a next-gen front-end testing tool specifically developed for modern web apps. Most of the modern testing tools including selenium operate in a certain way. They run outside of the web browser and execute different remote commands.

On the other hand, Cypress operates directly within a web or internet browser. This in turn helps Cypress to modify the behavior of the browser by altering network responses and requests and through DOM modulation.

Node Installation

Most of us would be probably familiar with Node.js. If you are not, then it is a server-side runtime environment built on top of the V8 JavaScript engine of Chrome. The free and open-source Node.js is used by millions of developers from all over the world.

In the runtime environment, Node.js has everything required to run a program that is written in JavaScript. However, you will need to install the Node JS framework before you start working on building a Node.js application.

Install Visual Studio Code

Visual Studio Code editor is a strong source code editor, but it is extremely lightweight. The editor, which runs on a desktop, is available for Linux, macOS, and Windows.

Another significant aspect of Visual Studio Code editor is that it comes with built-in support for Node.js, TypeScript, and JavaScript. That’s not it because the editor has a fine selection of extensions for runtimes (Unity and .NET) and other languages (Python, PHP, Java, C#, C++, and more).

Cypress Installation

You will be able to easily and quickly download Cypress from Cypress CDN. The latest version of the tool can be downloaded by clicking on the direct download option. The file will be downloaded to your laptop or desktop as a zip file. You will need to extract the zip file before you start working.

However, you will also be able to download Cypress from npm. The advantage of downloading through npm is that it will give you a clear idea of how to set up a new basic project with Cypress and package.json installed with it.

Also Read: Cypress Interview Questions

Cypress Test

Mocha and chai, which are some of the most popular assertion libraries in the JavaScript framework are the basis of Cypress. As a result, it adheres to the exact same style of writing test cases as other popular JavaScript frameworks. The default folder structure provided by Cypress will be used to write and manage test cases in the Cypress Workshop project.

Cypress Test Runner

Cypress features a unique test runner, which makes it possible for users to see commands as they are being executed. In addition to that, the test runner is capable of displaying the application’s real-time run under the test.

Users will be easily able to complete their first automated test with the help of Cypress. And, that test case can be executed by using the Cypress Test Runner. During the process, you will learn about the different components of the Cypress Test Runner and how to operate it with the terminal.

Locator in Cypress

Cypress also comes with multiple locators. Locators can be defined as the backbone for all types of automation frameworks for web-based apps. Locator also serves the crucial purpose of an identifier, which tells GUI elements like Check Boxes, Buttons, and Text Box that they need to operate to complete a certain process.

In addition to that, Cypress makes use of locators to detect the UI elements for apps under test. An important point to note is that Cypress supports only CSS selectors, which is why most Cypress automation code contains CSS selectors.

Get & Find Command

The web elements that are based on the locators can be searched in two different ways when using Cypress and they are called Get and Find. The result obtained by using both these methods is pretty much the same. However, it is integral to note that each method has a certain place of implementation and significance.

Cypress Asynchronous Nature

Asynchronous programming can be described as a means of parallel programming, in which a unit of works will be run separately from the main app thread. The purpose of parallel programming is to notify the calling thread about its progress, failure, or completion. These are non-blocking programs.

When you are executing synchronous programs, you will have to wait for the program to complete before moving to another task. However, when you are executing something asynchronously, you can move on to another task without waiting for the existing program to get completed.

Non-Cypress Async Promises

If you are familiar with Cypress, you would be aware of the fact that Cypress handles the asynchronous behavior of commands internally. Even though Cypress does this internally, it’s capable of offering a consistent, sequential, and seamless execution of test cases.

That said, there are situations, where the asynchronous promises or commands have to be handled explicitly. For instance, you will need to do this when combining Cypress commands with JavaScript commands or third-party libraries.

Cypress Assertions

The validation steps, which determine whether a certain step of the automated test case has succeeded or not are called assertions. Assertions serve the crucial function of validating the desired states of applications, objects, and elements under test.

For instance, assertions will help users to validate scenarios like whether a certain element is visible or not. All automated test cases must have assertion steps if not, it will become almost impossible to validate whether the app has reached the desired state or not.

Interacting With DOM Elements

Ui automation tools offer methods or APIs to interact with other web elements so the desired operations can be performed on the UI element. Apart from this, the APIs or methods offered by the UI automation tools assist in the user journey simulation. Cypress offers multiple commands that can stimulate the interaction of users with the application.

Key features Of Cypress

Let us now take a quick look into the three key features of Cypress, which are debuggability, real-time reloads, and automatic waiting.


Cypress offers users the unique ability to debug their applications under test directly from the Chrome dev-tools. One of the best things about Cypress is that it doesn’t just give error messages to the user, but also gives insight on how to approach and possibly fix the error.

Real-Time Reloads

Cypress is an intelligent and innovative tool and one of its best features are real-time reloads. Cypress is smart enough to realize that users will probably return to the test files that they have saved to rerun it after a while. So, what Cypress does is that it automatically triggers the run as soon as you save the file. As a result, users will not have to automatically trigger the run.

Automatic Waiting

Another highlighting feature of Cypress is automatic waiting. The tool automatically waits for processes to end. This means that Cypress waits for the animation to be fully completed, elements to become visible, AJAX calls to finish, DOM to load, and more processes to get completed. This eliminates the need to define explicit and implicit waits.

Final Thoughts

It is true that Cypress is currently being dubbed as the next big thing, but several developers are still unsure if Cypress will be able to completely take over Selenium. That said, the impressive set of Cypress continues to impress us, which is why you should definitely try it before debating between Cypress and Selenium.

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Subscribe to get IQ's , Tutorials & Courses