Menu

How to integrate API tests hosted in Postman's Team Workspace to Azure DevOps?

My previous blog post covered how to use Postman in API testing and integrate API test execution to Azure DevOps pipeline. Described solution assumed that API tests where exported to JSON-file which was added to the source control. Handling and maintaining API test JSON files in source control is not the most straightforward solution. This blog post shows how you can use Postman Workspace to maintain your API tests in cloud and share access for the team.

What is Postman's Team Workspace?

Postman's Team Workspace is a collaboration space for the team in the cloud. With team workspace, you can invite team members to collaborate on your API work within a workspace. Depends on the Postman plan you can invite multiple team members to the Workspace. Currently Postman Free plan enables to invite up to three members. To use team workspace for more than three members, you'll need the Postman Team, Business, or Enterprise plan.

Workspace members can comment on elements, use and change elements, or even fork from existing elements. Versioned history of all your changes is also available so anyone you invite to your team workspace can collaborate safely and effectively. Source

Especially from API test point of view notice that Postman Plans has different limitations for how many calls to Postman API is allowed per monthly. If you have a Basic Plan you can call Postman API 10000 times per month.

undefined

Source: Postman API Platform - Plans and Pricing

How to create Team Workspace?

Team Workspace can be created directly from the native Postman client or from the web interface. You can decide visibility level of the workspace between the following choices: Personal, Private, Team or Public.

undefined

When workspace is created you can start creating Collections and API tests.

undefined

How to integrate API tests from Team Workspace to YAML based pipeline in Azure DevOps?

Integration overview

YAML based CI/CD pipeline orchestrates build, deployment and execution of the API tests which are hosted in the Postman Team Workspace. API-tests requires system-to-system authentication (client credential flow) in this case. 

undefined

Integration between Postman and Azure DevOps

Newman CLI tool supports directly Postman's Team workspace so you can just easily point configuration to workspace instead of JSON based API test files.

Before starting

You need to have Postman Collection Id and API key to able to use Postman API endpoint when executing API Tests.

Postman API key

Postman API key enables you to communicate with Postman API endpoint. API key can be generated from Team workspace settings page https://[my-workspace].postman.co/settings/me/api-keys. After API key is generated persist key to Azure Keyvault. 

Note that API key will be invalidated after 60 days of inactivity by default.

undefined

Postman Collection Id

Postman Collection Id is a unique identifier for API test collection. Typically I have structured Postman Collections so that each API has an own collection. You can get collection Id from the Postman client or executing the following GET-operation

GET https://api.getpostman.com/collections?apikey={{postman_api_key} 

Integration steps

Configure the following tasks to your YAML-pipeline / template.

1. Install Newman CLI tool

Newman is a command-line Collection Runner for Postman. It enables you to run and test a Postman Collection directly from the command line. It's built with extensibility in mind so that you can integrate it with your continuous integration servers and build systems. Source

- task: Npm@1
  displayName: Install newman CLI
  inputs:
    command: custom
    verbose: false
    customCommand: install -g newman

2. Get Postman API key from Azure Keyvault

Later you can get Postman API key from the variable called $(postman-api-key) 

- task: AzureKeyVault@2
  displayName: 'Get Postman API key value'
  inputs:
      azureSubscription: ${{parameters.azureDevOpsServicePrincipalName}}
      KeyVaultName: ${{parameters.keyVaultResourceName}}
      SecretsFilter: 'postman-api-key'

3. Execute API tests

First parameter of Newman is Postman API address with API key and Collection Id. This sample command reads Postman environment variables from the file and appends some sensitive variables.

- task: CmdLine@2
  displayName: Execute integration tests
  inputs:
    script: newman run https://api.getpostman.com/collections/${{parameters.postmanCollectionId}}?apikey=$(postman-api-key) 
-e $(Build.SourcesDirectory)/${{parameters.environmentFilePath}} 
--env-var clientId=${{parameters.idpClientId}} 
--env-var clientSecret=$(${{parameters.idpClientSecretKeyName}}) 

Summary

If you want to use Postman based API tests then integration to Team workspace is really nice possibility. Basically you can maintain your API tests directly in Postman and latest version is always available when API tests are executed in Azure DevOps. 

Comments