Postman tests in jenkins

29
Postman tests in Jenkins Integration of postman collection for REST API testing into Continuous Integration flow

Transcript of Postman tests in jenkins

Postman tests in Jenkins

Integration of postman collection for REST API testing into Continuous Integration flow

Postman collection. Definitions

● Request (defined REST API request with a set of validation tests)● Folder (set of Requests)● Collection (set of Folders and Requests)

Collection should be considered as “root” folder for your project. Folders can be used to organize requests by component, by feature, by date or any other groups.

Postman. Collection example

How to integrate created tests in CI?

● Export environment variables● Export collection● Push exported files to Git (or other VCS)● Install NodeJS and NPM on your CI server● Install newman on CI server● Add CI job (or task/action/rule depending on CI terminology) to run newman

after deploying your REST API

Export Postman tests

Postman. Export environment variables

Postman. Export collection

Push files to Git (e.g. Github, Bitbucket or local Git server)

Setup prerequisites

Install prerequisites

● NodeJS and NPM https://nodejs.org/en/download/● Newman command line tool https://www.npmjs.com/package/newman● Git

NOTE: these tools should be installed on your CI server (e.g. Jenkins)

Jenkins job configuration

Jenkins plugins to install

● Email Extension Plugin● Git plugin (in most cases is installed by default)

Steps for adding Jenkins job

1. Create job with desired name and “Freestyle project” type;2. Enter URL for your git repository under “Source Code Management”;

a. Add credentials in case you are using private git repository;b. Specify branch you would like to use (“master” by default)

3. Click on “Add Build Step” > “Execute shell” under “Build” section.4. Type newman command to run collection (newman run <collection_file_name> -e

<env_var_filename>)5. Configure Email Notification under “Post-build actions” section.6. Configure your deployment job to trigger

Jenkins. Create new job

Jenkins. Specify git repository

Jenkins. Add “Execute shell” build step

Jenkins. Enter newman command with path to collection file and file with environment variables

Jenkins. Configure Email Notification. Step 1

Jenkins. Configure Email Notification. Step 2

Jenkins. Configure Email Notification. Step 3

Jenkins. Configure Email Notification. Step 4

Jenkins. Configure Email Notification. Step 5

Is it the final step?

Run it!

Jenkins. Console output

Jenkins. Console output

● Open your existing Job (the one that is used for application deployment)● Click on “Configure”● Select “Build other projects” under “Post-build Actions” section● Enter name of your job with newman command● Save

Trigger your new job from another

Jenkins. Post-build action to trigger job with Postman collection

What we have used?

Summary of the tools used

● Postman for creating tests● Newman for running them on

server● Git for storing your collections

and variables’ file● Jenkins to trigger newman

command in certain conditions (after deployment, daily, on demand, etc)

ThanksQuestions?

Example files used in presentation can be found at https://github.com/qaclub/postman_collection_example