Firstly,cypress is an automation test tool for the modern web and can be used for a different type of testing like
we will be using cypress for E2E testing in node.js and E2E testing in node.js is an important part of software development in node.js
Above all, we are going to write a test case for a simple blog application: https://gentle-tor-26434.herokuapp.com/
source : https://github.com/ganeshmani/meanstack_task
Therefore, we need to figure out how it has to work and what logic we need to test
For this blog application, we simply going to test :
Firstly,we will setup the cypress in the project
1npm install cypress --save-dev
Once the installation gets completed, you will see the folder structure of cypress as
Let's breakdown the functionality of each folder that cypress has
beforeEach
within any of the cypress/support
files:1beforeEach(function() {2 cy.log("I run before every test in every spec file!!!!!!")3})
Firstly, create a file in the cypress/integration folder and add the following code.
1describe("Loading the homepage", function() {2 it("successfully loads", function() {3 cy.visit("https://gentle-tor-26434.herokuapp.com/")4 })5})67describe("adding blog post", function() {8 it("creating a new blog post", function() {9 cy.visit("https://gentle-tor-26434.herokuapp.com/")1011 cy.get("input").type("Cypress added blog post")1213 cy.get("textarea").type(14 "Hey it is an automated testing blog post.please check it out the cypress.io...it' so cool"15 )1617 cy.get("div.submit").click()1819 cy.get("div.item")20 .last()21 .should("contain", "Cypress added blog post")22 })23})
After that, we can run the cypress command to start the cypress interface:
1$(npm bin)/cypress open
there are several other ways to do that https://docs.cypress.io/guides/getting-started/installing-cypress.html#Opening-Cypress
it will open a cypress interface like this.
select the test case that you want to run or you can select Run all specs
Output for the cypress test cases
In conclusion, cypress run the test cases and return the assertion in the browser. Yayyyy!.. we did it :-)
To learn more about cypress. https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html
To learn more about Node.js . https://cloudnweb.dev/category/web-dev/
Happy learning!!!!! :-)
No spam, ever. Unsubscribe anytime.