Once the execution is finished, the results can be seen on the right side of the screen. At the top, a summary will appear in which you can see how many tests failed, how many failed, and how long they took to run. The same will appear below, but for each request made. Number of times we want to run the tests. To run the tests we must follow the following steps:Ĭhoose to run the entire collection or just a folder.Ĭhoose the environment where we have the variables stored. Once we have all the requests we want together with their tests, they can be run together. For that we need to open the "Collection Runner": In this case one of the 2 tests failed because it was specified in the tests that it was expected to receive more than 100 ships and if we look at the information received there are fewer. To execute the created request, you must first save it (Important!) And then send it by clicking on “Send”. We are interested in two parts of the answer: Body, where we see the json returned by the server with all the information and Tests, where the result of the asserts will be seen. Or in a folder. Storing them in folders has the advantage of being able to isolate their execution from the rest of the requests. The next step would be to save the request by pressing the "Save" button and choosing where to save it. We have the option of saving it directly in the collection: In this test we have an assert that verifies that the status code is 200 and also a loop to store information about a certain ship of all the returned ones in an environment variable. On the right side we have a series of pieces of code that help the user to create tests. The second part of creating a request is the Tests section, designed to create asserts that verify that the information returned by the server is what we were expecting and values can also be assigned to new environment or global variables to use later. For example: ĪPI: The full address would be /api/starships, but since we already save /api in the host environment variable we just have to write to use it. Method: It can be GET, POST, PUT, DELETE. In this example we try to get a list of spaceships, so in the screenshot you can see: Then we can create a request, which will look something like this: Postman allows you to create collections to store requests, so the first thing we need is to create a collection, providing its name (required) and a description. This API does not need the user to authenticate, but if it did, we could save the username and password in the environment. The first thing we have to do before starting to create tests is to prepare an environment for the server in which the tests will be run. To create an environment we go to Manage environments → Add. Then we can start adding key-value pairs corresponding to variables that we will use multiple times in requests.Īs an example, I have chosen the following API to explain how it works: /api , so we are going to save it in a variable that we will call host: "The main objective of Postman is to help build APIs quickly allowing the agile creation of requests and workflows through collections" Environment The first program that we are going to use to achieve test automation is Postman, which can be defined as follows: The test automation is to use a program to control the execution of tests and check if the results are what we were expecting. To explain how to automate tests on an API, three programs will be needed: Postman, Newman and Jenkins. Test automation for an API: Postman, Newman and Jenkins What is test automation?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |