Skip to content

Sample implementation of DevOps pipeline to automate API testing via postman

License

Notifications You must be signed in to change notification settings

grnisha/APIM-testing-with-postman-in-ADO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APIM testing - configure Postman API tests in Azure DevOps

This example is exporting an already existing API from Azure APIM into postman and configuring Postman API tests in Azure DevOps. For this example I am using demo conference API, which is configured in my APIM instance. Find more details here.

Steps

Export the api from APIM and select postman. You can choose postman for Web or Windows. image

image

This will prompt a dialogue in postman to select a workspace. Once you have selected the workspace, import the api into postman. There is also an option to create collection at the same time and some advanced options

image

Now that the API is exported to postman, configure any pre-request steps, variables & tests in postman. In this example, GetSessions endpoint uses a pre-request step to retrieve jwt-token.

image

There are several variables configured in this example as shown below.

image

The test configured in this example is checking if the API response status is 200. Additional tests can be easily added here , e.g. – tests to check response content, response time etc.

image

After configuration is completed, execute the tests to check if everything is working as expected.

image

Once everything is working as expected, click on the collection and export it. From the dialogue, select Collection 2.1 and save the json file.

image

The exported json file also contains the variables we have configured originally (baseUrl, apiKey etc). I have updated values of these variables with place holders (##apiKey##, ##baseUrl## and created a variable group in ADO ‘DemoConfAPIGroup’ to define the values of these variables. You can link this variable group to a Key Vault to securely save sensitive data. The placeholders in json file will be later replaced with required values from variable group during pipeline execution.

image

Now we have the exported and updated json file, let’s move on to creating DevOps pipeline. To run this collection in DevOps pipeline, we need to use newman CLI tool from postman. We can install this tool using npm command (npm install -g newman). To run the tests, we can use the command newman run DemoConfApi.json. The yaml definition for devops pipeline is in azure-pipelines.yml.

The newman run command comes with a few more parameters, which helps to publish the test results. Please note that the -x flag will ignore the exit code and continue executing build steps in the pipeline. If you want to stop the pipeline execution on tests failure, remove this flag.

Here are the test results after running pipeline:

image

About

Sample implementation of DevOps pipeline to automate API testing via postman

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published