Smooth Web Services Testing with Axios and NodeJS
Kushan Shalindra Amarasiri
Director Quality Engineering at Social Catfish
As a good practice we should test web services initially rater than just waiting for the solution to come with the UI integrated. Manual testing of Web Services testing is done through tools like SOAP UI or Postman. We will be sending the necessary parameters to the desired end point and make sure that we receive the required response from the services.
At present we will be automating these test cases rather than performing them manually. There are so many test automation tools available for testing Web Services. REST Assured be the dominated open source testing tool. One of the Web Services testing tool that I'm going to cover today is Axios module in NodeJS. With Axios, we can test Web Services smoothly in the following way. First we should download and install Axios using the following npm command.
npm install axios
Next lets create the test scenario to test a Web Service provided by NASA. Lets script the automated test case in the following manner.
const axios = require('C:/Users/lkkushan/node_modules/axios');
axios.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY')
.then(response => {
console.log(response.data.url);
console.log(response.data.explanation);
})
.catch(error => {
console.log(error);
});
Its very much easy and you should also notice that Axios is the most light weight web services testing module.
Lets execute the test case that we have scripted with the following node command.
C:\slimerTest\httptest>node C:\slimerTest\httptest\kushan5.js
If everything is great we will be seeing the contents of the response in the command line.