Загрузка...

Postman Test API Tutorial: Your First Test Script & Examples

Are you trying to learn how to test an API with Postman? This tutorial is the perfect place to start. We'll show you how Postman is a powerful test tool that allows you to automate the validation of your REST API responses.

In this step-by-step guide, you will learn how to write your very first Postman test script. We'll start with the basics, like finding the "Scripts" tab (formerly the "Test" tab) and using snippets to generate code. You will see a complete Postman test example where we create a small test suite to validate an API response, including checking the status code and the JSON data.

✅ In this video, we will cover:

(0:00) Why you need an API Test Tool like Postman
(1:00) Finding the "Scripts" tab (the new "Test" tab)
(2:15) Postman Test Example: Your First Test Script
(3:30) How to Test a REST API for a "200 OK" Status Code
(5:00) Creating more Test Cases for the Response Body
(7:10) Viewing your completed Test Suite in the results.
By the end of this video, you'll have the confidence to write basic test cases for any API you work with in Postman.

====================TEST SCRIPT==================
// Variable to store the parsed JSON response
const jsonData = pm.response.json();

// Test 1: Check for a successful 200 OK status code
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

// Test 2: Check for the correct username in the JSON body
pm.test("Username is 'emilys'", function () {
pm.expect(jsonData.username).to.eql("emilys");
});

// Test 3: Check the data type of the user ID
pm.test("User ID is a number", function () {
pm.expect(jsonData.id).to.be.a('number');
});

// Test 4: Check if the response time is within an acceptable range
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});

// Test 5 (Bonus): Check if a response header exists
pm.test("Content-Type header is present", function () {
pm.response.to.have.header("Content-Type");
});

==================================================
#Postman #APITesting #PostmanTest #RESTAPI

Видео Postman Test API Tutorial: Your First Test Script & Examples канала QA and Dev Tips
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки