Home / Blogs / Article

Welcome to Cypress Test Automation

Tutorial 1 – Introduction to Cypress

Welcome to Cypress Test Automation & this is the first tutorial in this web automation series. There is a lot of buzz around cypress today and given the passionate community built around it, this buzz will definitely going to sustain in the future! We will start with learning the basics of this wonderful tool and slowly would be expanding our knowledge around it.  In this tutorial we are going to introduce you about cypress. So let’s begin!!

What you will Learn :
What is cypress and why is cypress generating so much interest in the market?
Cypress Tool Overview
Cypress Architecture
Cypress ecosystem/components
Cypress Limitations
How are commands executed?

What is cypress and why is cypress generating so much interest in the market?

There is a lot of buzz around cypress today because cypress is different!

The official cypress documentation https://www.cypress.io/features/ lists out a few ‘Game Changers’

Cypress Test Automation

Let us go through them and other benefits to understand why cypress is different:

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Test Automation

Cypress Tool Overview

Open cypress and you will see 3 tabs:

At the right hand side, you can see the different browsers that are supported
Cypress Test Automation

You can run all you tests by clicking ‘Run all specs’ (a spec is same as Test)
Cypress Test Automation

Let us click any Test (example-MyFirstTestScript.js)
Cypress Test Automation

The actual UI from cypress opens
Cypress Test Automation

This is how the cypress looks like. Our application is running on our right and the Tests are shown on our left ‘Verify Page Title – Positive TC’
Cypress Test Automation

Let us click the Test ‘Verify Page Title – Positive TC’.

That would show up all the steps in our Test. So, for example, in step 1, we are visiting a website and in steps 2/3 we are verifying the page title.
Cypress Test Automation

When you hover over different steps, you will see application actually changes on our right.

We can click any step and can debug. Each one of these commands takes the DOM snapshot which can be used for debugging. For any step, you can see the snapshot at the ‘request’ & ‘response’ stages
Cypress Test Automation

Cypress Test Automation

Below is another Test where we have clicked ‘type’ step on left hand side. You can see 2 DOM snapshots: before and after

Below is ‘before’ snapshot (value 2 still not typed)
Cypress Test Automation

Below is ‘after’ snapshot (value 2 typed). This is also called as Time-travel

Also Check: Selenium Python Training

Cypress Test Automation

You can inspect the ‘type’ step & click ‘Console’. You can see the command as ‘type’, the typed value as ‘2’, the element it was applied to and so on. So these things help you in debugging.

Cypress Test Automation

Also Check: Selenium Online Training

Cypress Architecture
Let us first have a look at Selenium architecture overview:
Cypress Test Automation

This is general overview of selenium architecture. Selenium is a client server architecture. Every client command is converted into json and is sent via HTTP to selenium server. The server forwards that request to the browser’s native automation APIs. There are many round trips involved & hence slight latency/slowness. All of this stuff is NOT executed inside the browser, its running outside of the browser.

Now let’s take a look at cypress architecture and see how it is different.

Behind cypress, there is a node.js process.
Cypress Test Automation

The Node.js process does a couple of things. For instance, when launching a browser, it will STOP the browser with the proxy being set. So there is a proxy provided by cypress and browser runs with that proxy. So Node.js will start the browser with that proxy.

The next thing is that, Node.js will open up an HTML page that contains 2 iframes:
one for our cypress Tests which are executed on local host and another one for our application. So basically, you will see cypress Tests being executed on our left and application on our right. Those are basically the 2 iframes.
Cypress Test Automation

Cypress Test Automation

Normally, we cannot communicate between iframes, because our application can run on a different domain and may not be on localhost. The trick here is, what cypress does is, since it launches the browser page and it has access to that page, it injects a script which sets the application’s domain to localhost. Now both the frames are running on the same domain, we can now communicate between 2 iframes. This is what allows cypress to easily access all the objects, like DOM (html properties of webpage), Windows, etc from within our Tests, because both are running on the same domain
Cypress Test Automation

There is a websocket connection between cypress instance inside the browser and Node.js process for anything that requires higher order privileges, like, cypress has access to OS, it can take screenshots, it can record videos etc
Cypress Test Automation

What does the proxy do? A proxy server acts as a gateway for HTTP requests from clients seeking resources from servers that provides those resources. So for every HTTP request that goes out of the browser, it goes through the proxy, out to the WEB and back to the browser. So cypress operates on a network layer and it can control and alter every HTTP request.
Cypress Test Automation

So this is how cypress works. What you have to understand is that, everything runs inside the browser. Our Tests are executed inside the browser in the same run loop as our application.

In summary: Cypress runs inside the browser and uses Node for anything outside of the browser

Cypress ecosystem/components

Cypress has 2 components:

Cypress Limitations

How are commands executed

Everything is going to happen in order that you wrote your tests. So see below. Here, you want to get the todo list element and you want to make the assertion that it does not exist
Cypress Test Automation

So this was an introduction to cypress. In our next tutorial, we would learn how to install cypress on a windows machine.

Thank you for reading!

Also Check: API Testing Training

← Back to all blogs