Member-only story

API testing with Cypress

Siddharth Murugan
2 min readSep 5, 2021

--

Make API call with Cypress

When I getting started with Cypress, it was very difficult to call API from Cypress spec file. When we migrate from one testing framework to another we may feel very difficult to make use of already existing API call functions which we have written in Javascript. I thought of sharing a way which we can reuse the same Javascript code in Cypress. Lets get started!!

NPM package:

npm install cypress
npm install axios

Sign up weather API

To demonstrate this API call, I have made use of public weather API and you can sign up here.

Once you are done, you will get a secret API access key which you can use it to access the data. Try to call the same API with POSTMAN manually to confirm whether it is working fine.

I got 200 status code from postman

Creating Javascript function

It’s time to create a API function to capture the response from the GET request. I am using axios to make GET request. Below is the piece of code created by me for making API call,

--

--

Siddharth Murugan
Siddharth Murugan

Written by Siddharth Murugan

Programmer who loves to do things creatively. #automationTester by profession #javascript #nodejs #reactjs

Responses (1)