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? You can use a wide variety of other configurations to make your collection more dynamic.Posted on 2 of August of 2016. You can set up notifications and customize Jenkins as per your needs. In a bigger setup, Newman will be part of your build process and probably not the entire process. Jenkins will now run Newman at your desired frequency and will tell you whether the build failed or succeeded. Note: 30 can be replaced with another number The syntax for setting the frequency is H/(30) * * * *. To set up the frequency with which Jenkins runs Newman, click on “Configure project” in the main project window and then scroll down.=. Jenkins indicates that the build succeeded with a blue ball. You can move on once you see green pass icons for all your tests like the screenshot above. We can check why with the console output from Newman.Ĭlick on the “Console Output” link in the sidebar to see what Newman returned.įix these tests inside Postman and then try again. Jenkins indicates that the build has failed with a red dot in the title. Run this build test manually by clicking on the “Build Now” link in the sidebar. This denotes that Newman is going to exit with this code that will tell Jenkins that everything did not go well.Ĭlick the Save button to finish creating the project. Note here that we are using the Newman command parameter “exitCode” with the value 1. $ newman jenkins_demo.postman_collection -exitCode 1
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |