Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
API Testing with Jest & Axios | Intro to Intermediate Automation Testing
Introduction to QA Automation Testing
course content

Contenido del Curso

Introduction to QA Automation Testing

Introduction to QA Automation Testing

1. Introduction to Automation Testing
2. Using a Test Automation Framework
3. Browser Automation with Selenium
4. Intro to Intermediate Automation Testing

API Testing with Jest & Axios

In the previous course, we utilized Postman to perform API testing. However, that was from the perspective of Manual Testing.

In Automation Testing, to effectively perform API testing, we would require some kind of a JavaScript method which enables us to make HTTP requests through code.

Axios is a perfect choice in this scenario. It is a Node.JS library which allows us to programmatically make API requests.

The two methods which we will be looking at are:

The usage of these methods is demonstrated in the following video:

For-example, we can make a GET request to the api/posts endpoint using the following code:

The HTTP Request methods return a response object containing all the data of the HTTP response. We can use the await key for the method to return that object and store it in a variable:

Since we are using await, we need to enclose the code inside an async function:

From the response, we can extract the Status Code of the response using the status attribute of the response object. The response data can be extracted from the data attribute of the response object.

It's imperative to enclose the code inside a try-catch block to make sure the program does not crash in case the HTTP request fails - since the get and post methods raise exceptions in case of request failure.

The post method can be used for making a POST request. The usage is very similar to a GET request:

1. What is Axios, and why is it used in Automation Testing for API testing?
2. Which of the following is a correct way to make a GET request using Axios?

What is Axios, and why is it used in Automation Testing for API testing?

Selecciona la respuesta correcta

Which of the following is a correct way to make a GET request using Axios?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 1
some-alt