Know your test automation tools : Web Services Test Automation with Cypress
Kushan Shalindra Amarasiri
Director Quality Engineering at Social Catfish
Cypress is a growing test automation tool in the industry and its capabilities are rapidly growing. Lets look at how we can kick start web services test automation with Cypress. First of all let's install Cypress.
First we have to download and install Node.js as it uses Node.js and run on top of it.
??? npm install cypress
The cypress installation will be downloaded and installed in your machine.
After installing open up Cypress.io test runner by typing the following command in your command line.
node_modules\.bin\cypress open
It automatically takes the available .js files in your ..\cypress\integration folder. Next create the following code snippet in your favourite js editor or notepad.
describe("Testing?API?Endpoints?Using?Cypress",?()?=>?{
????it("Test?GET?Request",?()?=>?{
????????cy.request("https://localhost:3000/employees")
?????????????.then((response)?=>?{
????????????????????expect(response.status).to.eq(200);
????????????????????cy.log(JSON.stringify(response.body));
????????})
??})
??it("Test?POST?Request",?()?=>?{
????cy.request({
????????method:?'POST',
????????url:?'https://localhost:3000/employees',
????????body:?{
????????????"first_name"?:?"Kushan",
????????????"last_name":?"Amarasiri",
????????????"email"?:?"[email protected]"
????????}
???}).then((response)?=>?{?
???????expect(response.status).to.eq(201);
???????cy.log(JSON.stringify(response.body));
???})
})
it("Test?PUT?Request",?()?=>?{
????cy.request({
????????method:?'PUT',
????????url:?'https://localhost:3000/employees/2',
????????body:?{
????????????"first_name"?:?"Kushan",
????????????"last_name":?"Amarasiri",
????????????"email"?:?"[email protected]"
????????}
???}).then((response)?=>?{?
???????expect(response.status).to.eq(200);
???????cy.log(JSON.stringify(response.body));
???})
})
})
Also please be mindful to install and configure the sample web service.
└? ? Microsoft? Most Valuable Professional (MVP) ? Linkedin Top Quality Assurance Voice ? DZone Core Member ? Applitools Ambassador | Read My Blog at qaautomationlabs.com | AWS,PMI-ACP?,ITIL? PRINCE2 Practitioner?
3 年Thanks for Sharing Kushan Shalindra Amarasiri