Hi there!
Today, I'll demonstrate how you can enhance the simplicity of your API testing using AI within Postman.
What is Postman?
Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIsâfaster.
Setting up the environment.
To begin, we require some endpoints for testing purposes. To fulfill this requirement, I've set up a dedicated server. If you're unfamiliar with Docker and Git, there's no need to worryâI've prepared comprehensive instructions on how to install them (Docker/docker-compose and git installation guidelines can be found towards the end of the article). Once you have Git and Docker in place, you can proceed next:
Ensure port 8080 is unoccupied; the application is operational on this port.
You need to clone a
-
open in terminal (or an equivalent) and run commands:
git clone https://github.com/PavelMal/PostmanTesting.git
cd PostmanTesting
docker-compose up
Please wait for approximately 1-2 minutes, and after this time, you should observe a log entry resembling the following:
Starting qa-server ... done
Attaching to qa-server
âŚ
âŚ
qa-server  | 2023-08-10 05:19:17.741 INFO 1 --- [main] com.test.Application: Started Application in 5.183 seconds (JVM running for 6.1
This indicates that the application is now operational. To verify its proper functionality, simply initiate a request to:
http://localhost:8080/api/check
Expect a response status code of 200 OK.
Your progress is commendable. We have now successfully configured the testing environment.
This application offers the capability to generate and retrieve orders (an order being an object comprising three attributes: id, name, and price). Don't hesitate to utilize Swagger for this purpose: http://localhost:8080/swagger-ui.html#/
(It's not in vain that I added it to the project. đ)
Generate the initial order and tests to verify this functionality
Letâs move on to the most interesting part - open the Postman and create your first order
Well done! At this point, we can begin creating tests for that specific endpoint. However, before we proceed, consider this: we have an AI assistant at our disposal. Let's experiment with its capabilities.
- Click on âTestsâ tab
- Click on AI assistant button
- Write âAdd tests to this requestâ and submit it
Youâve got your first set of tests including checking response time.
Try other prompts such as:
- Test for response content type
- Test for response schema
- Test for response data length
- Test for response time within acceptable range
Validation of error message
Let's proceed to create tests for the validation of error messages. In Postman, input a price of 0 and initiate a request. This action should result in a response code of 400 along with the following message:
"message": "Price can't be less than or equal to 0".
Leverage the AI assistant to compose a script:
response message should be "message": "Price can't be less or equal than 0"
You now possess two tests designed to check the 400 status code and verify the error message.
Great job!
I've included the logic to check the name/price/ID body parameters. Your task is to identify all possible scenarios and harness AI assistance to generate the corresponding tests.
Visualize response
Another valuable feature is response visualization. Let's explore it together. Type 'Visualize response as table' and see the magic
Postman collections
Last but not least, do not underestimate the value of utilizing collections, as this will enable your tests to maintain a structured framework. By employing collections, you can effortlessly oversee API requests alongside sets of tests.
I appreciate your attention! You are now prepared to harness AI for your API testing needs (Furthermore, you have acquired the fundamentals of Docker and Git).
Would greatly appreciate it if you could star my project.
Installation instructions for git
Ubuntu:
Open a terminal.
-
Run the following command to install Git:
sudo apt update
sudo apt install git
Once the installation is complete, verify it by typing:
git --version
macOS:
- Git is usually pre-installed on macOS. However, you can ensure you have the latest version by opening a terminal and typing:
git --version
- If Git is not installed or you want to update it, you can install it using Homebrew (a popular package manager for macOS):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install git
Windows:
- Download the Git installer for Windows from the official Git website:
Git for Windows - Run the installer and follow the on-screen instructions. You can usually leave the default settings as they are.
- During the installation, you'll be asked to choose a default text editor and adjust line ending conversions. You can stick with the default options or make changes according to your preferences.
- After the installation is complete, open a Command Prompt or Git Bash (included with Git for Windows) and verify Git by typing:
git --version
Installation instruction for docker/docker-compose
Ubuntu:
- Install Docker:
Open a terminal and run the following commands:
sudo apt update
sudo apt install -y docker.io
- After the installation is complete, start and enable the Docker service:
sudo systemctl start docker
sudo systemctl enable docker
-
Install Docker Compose:
Run the following commands to download the latest version of Docker Compose:sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
macOS:
- Install Docker Desktop:
Download Docker Desktop from the official website and follow the installation instructions: - Docker Desktop for Mac
Docker Desktop includes both Docker and Docker Compose.
Open a terminal and verify that Docker and Docker Compose are installed:docker --version
docker-compose --version
Windows:
- Install Docker Desktop:
Download Docker Desktop from the official website and follow the installation instructions: - Docker Desktop for Windows
Docker Desktop includes both Docker and Docker Compose.
Open a Command Prompt or PowerShell window and verify that Docker and Docker Compose are installed:docker --version
docker-compose --version