Cypress: Fast, Easy and Reliable Testing
Cypress is an Automated frontend testing tool. Started by a team of frontend designers, Cypress has evolved to be one of the best tools for an end to end, integration and unit testing in modern web development. Writing and debugging tests are easy using Cypress.
Cypress tests are written on Javascript. It has been built to handle modern frontend frameworks easily. Cypress has its own architecture and does not use Selenium unlike other testing tools. It has its own DOM manipulation and runs directly on the Chrome browser.
Here, I will guide you through the setup process of Cypress and write a simple test in Cypress. Before installing Cypress, your machine needs to have node installed. Head over to NodeJS and install it on your machine.
$ node -v (check for successful node installation)
Now, you can install the cypress package using the npm command.
$ npm install cypress
The installation will take a minute or two depending on your internet connection. After the installation, you can run cypress using:
$ npx cypress open
You can run your tests directly clicking your scripts. Now that you’ve installed Cypress, let's move ahead and write a simple test in Cypress.
All your tests are written inside the integration folder in your Cypress directory. Add a new file new.spec.js inside the folder and write the small script below.
describe(“Go to Google”, () => {it(“successfully loads”, function() {cy.visit(“https://www.google.com")})})
The above script navigates to the Google website using the Chrome browser in the Cypress runner. Save your file and enter npx cypress open to initialize the runner. Click on the test script at the Cypress runner screen.
Congratulations, You successfully wrote your first test using Cypress. You can start building tests now. Cypress comes with amazing documentation to guide you through its offerings. Go ahead and Cypresssss !!