This project contains Postman collections that were written for the endpoint from opened swagger API.
Test cases you can see here.
There are used Postman Sandbox API: JavaScript pre-request and tests scripts.
A couple of tests realizes DDT techniques: test data are read from CSV or generated in pre-request script. Other test data are generated automatically and have random values.
Postman collection can be launched using Newman from the console or Jenkins. Newman creates informative reports.
Postman tests collection can be integrated into CI/CD.
Postman, Postman Sandbox API, JavaScript, Newman
- open command line
- check Node.js
node -v
- if Node.js doesn't find install version 8.X or 10.X from Node.js
- install Newman
npm install -g newman
- clone git repository
https://github.com/MaryGeraseva/5-postman-api-tests.git
- open project folder
cd 5-postman-api-tests
- run test collection with newman
newman run [$collection-name.json] -d [$external-data-file.csv]
- as an example
newman run POST_200_with_post200data.postman_collection.json -d post200data.csv
- external data files have to use only with POST_200_with_post200data.postman_collection.json (post200data.csv) and POST_400_with_post400data.postman_collection.json (post400data.csv)
- as an example
pipeline {
agent any
stages {
stage('download') {
steps {
git 'https://github.com/MaryGeraseva/5-postman-api-tests.git'
sh 'npm install'
}
}
stage('tests') {
steps {
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run delete-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run get-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run get-all-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run post-get-delete-get-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run headers-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run nonexistent-endpoint-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run not-allowed-method-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run post-200-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run post-400-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run post-400-with-post400data-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
sh 'npm run post-200-with-post200data-tests'
}
}
}
}
}
- on Windows:
pipeline {
agent any
stages {
stage('download') {
steps {
git 'https://github.com/MaryGeraseva/5-postman-api-tests.git'
bat 'npm install'
}
}
stage('tests') {
steps {
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run delete-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run get-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run get-all-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run post-get-delete-get-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run headers-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run nonexistent-endpoint-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run not-allowed-method-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run post-200-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run post-400-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run post-400-with-post400data-tests'
}
catchError(buildResult:'FAILURE', stageResult:'SUCCESS') {
bat 'npm run post-200-with-post200data-tests'
}
}
}
}
}
- safe and run job
Jenkins job builder is an additional application which takes simple descriptions of Jenkins jobs in YAML or JSON format and uses them to configure Jenkins.
Jenkins job builder files for this project and usage information in my next project.
- open command line
- clone git repository
https://github.com/MaryGeraseva/5-postman-api-tests.git
- import collections:
open Postman --> on the toolbar push "Import" button --> "Import File" --> "Choose Files" --> import files from downloaded repository
- run tests with Postman Runner:
on the toolbar push "Runner" button --> choose collection --> [optional] on the toolbar in section "Data" push "Select file" button--> run tests
a couple of collections have to run only with external data files: POST_200_with_post200data.postman_collection.json with post200data.csv and POST_400_with_post400data.postman_collection.json with post400data.csv
e-mail: mary.geraseva@gmail.com
telegram: @MaryGeraseva
skype: mary_geraseva
linkedIn