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

Postman tests in jenkins

Feb 19, 2017

Download

Internet

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Postman tests in jenkins

Postman tests in Jenkins

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

Page 2: Postman tests in jenkins

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.

Page 3: Postman tests in jenkins

Postman. Collection example

Page 4: Postman tests in jenkins

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

Page 5: Postman tests in jenkins

Export Postman tests

Page 6: Postman tests in jenkins

Postman. Export environment variables

Page 7: Postman tests in jenkins

Postman. Export collection

Page 8: Postman tests in jenkins

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

Page 9: Postman tests in jenkins

Setup prerequisites

Page 10: Postman tests in jenkins

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)

Page 11: Postman tests in jenkins

Jenkins job configuration

Page 12: Postman tests in jenkins

Jenkins plugins to install

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

Page 13: Postman tests in jenkins

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

Page 14: Postman tests in jenkins

Jenkins. Create new job

Page 15: Postman tests in jenkins

Jenkins. Specify git repository

Page 16: Postman tests in jenkins

Jenkins. Add “Execute shell” build step

Page 17: Postman tests in jenkins

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

Page 18: Postman tests in jenkins

Jenkins. Configure Email Notification. Step 1

Page 19: Postman tests in jenkins

Jenkins. Configure Email Notification. Step 2

Page 20: Postman tests in jenkins

Jenkins. Configure Email Notification. Step 3

Page 21: Postman tests in jenkins

Jenkins. Configure Email Notification. Step 4

Page 22: Postman tests in jenkins

Jenkins. Configure Email Notification. Step 5

Page 23: Postman tests in jenkins

Is it the final step?

Run it!

Page 24: Postman tests in jenkins

Jenkins. Console output

Page 25: Postman tests in jenkins

Jenkins. Console output

Page 26: Postman tests in jenkins

● 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

Page 27: Postman tests in jenkins

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

Page 28: Postman tests in jenkins

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)

Page 29: Postman tests in jenkins

ThanksQuestions?

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