Automation through Cypress is easy: Installation and Quick start
Overview
Testing is always an important part of software development because it ensures the quality and functionality of the system. There are two main types of testing: Manual testing and Automation testing. Automation supports manual testing and minimizes the burden for manual testers. If you want to learn the difference between automation and manual testing, you can click here.
There are many tools available for automation tests like Selenium, Telerik Test Studio, Robotium, and so on. Cypress is a modern automation testing tool for the front-end, written in JavaScript. Cypress provides different features like time travel, real-time reload, automatic waiting, screenshots, videos, and many more. It does not require specifying any web driver for Cypress to run the tests in the browser; instead, it runs the tests in the actual browser itself. It also supports modern single-page applications, making it a good choice for automation testing.
Prerequisites
Cypress uses JavaScript and runs along with Node.js, so Node.js needs to be installed on your device. You can follow the installation tutorials on Digital Ocean by clicking here. Choose your operating system, and you are good to go. Cypress is easy to install with just a single command if Node.js is already installed: npm install cypress --save-dev
. Let’s understand it step by step.
Quick Start
Let’s get started
The steps we will be going through are given below:
- Initialize the
package.json
file - Install Cypress using npm or yarn
- Running Cypress tests in the dashboard
At first, let’s create a new folder/directory. I will make one with the name first-cypress
and get into the folder:
Initialize the
package.json
file- For npm:
npm init
ornpm init -y
- For yarn:
yarn init
oryarn init -y
Provide proper information and press yes and enter.
- For npm:
Install Cypress using npm or yarn
- For npm:
npm install cypress --save-dev
- For yarn:
yarn add cypress --dev
This command will create a
node_modules
directory, which includes all the Cypress libraries.- For npm:
Run Cypress tests in the dashboard
- Now we have Cypress and its dependencies, we can run Cypress tests easily.
- Open the Cypress dashboard with the command:
npx cypress open
.
Cypress provides some example test files by default. Click the ‘ok, got it’ button and select the test you want to run. You can also click the ‘Run all specs’ button to run all tests.
Congratulations, you’ve completed the first setup and installation process. Here is the old folder structure of cypress (v<10) click here. Some of the structure is still same in Cypress. Now you are ready to take another step in cypress.
Go Ahead and learn