Running Postman tests on Jenkins using Newman and AWS (Ubuntu 14.04)

We will be using a hosted Ubuntu server so an AWS account is required

After creating an AWS account and accessing the console be sure to change the region from default to create the instance in the closest zone :


  • Select EC2
  • Select Launch Instance

  • Choose Ubuntu Server (build 14.04 at this current time):






  • Choose the default “Free Tier eligible’ instance
  • Leave the defaults and select ‘review and launch’ (I selected auto assign public IP)

Edit the Security groups to allow traffic in:

  • Namely port 8080 for jenkins (default port)
  • Port 22 for ssh access



  • The security groups should look something like this:


  • Choose Launch

  • Then Create the Keypair
  • Make sure the correct security group is assigned to that instance:


  • Once up and running select connect to get the terminal commands:



  • Open your terminal or command prompt and locate the .pem file that was saved and apply the following command to modify permissions on that file:



**If prompted select ‘yes’ to add the ssh key.

Note: I use a Node.js command prompt running on windows, this allows you to run all your windows and bash commands these commands are the same on a Mac but may differ from the windows default command prompt.


Proceed to run the following:

wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

Install NPM
apt-get install nodejs
apt- get install npm

npm install -g newman

Create a symlink to node:
ln -s /usr/bin/nodejs /usr/bin/node

Run(from the terminal):

service jenkins start



Create a suite of tests in Postman



  • Export the Collection and environment files to a local directory (the tests use a number of variables in the Prod environment file and are required for the tests to run)



Execution of the newman tests locally from the directory contains the environment and collection files:
newman -c json.postman_collection -e Prod.postman_environment -o testresults.json


Copying the files up to Ubuntu
(few options here):

  1. Use SCM from the commandline
  2. Use an FTP program
  3. Upload to a SCM (Ie Github) and point Jenkins to it

  • For simplicity sake I will be going with option 2

  • Install Filezilla
Add your .pem file to SFTP under settings/preferences:


  • Create a new connection and enter the public DNS in the Host field and ‘ubuntu’ in the User field eg:


  • Accept the Unknown server key prompt:



Upload the files to the Ubuntu instance:


Create a tests folder and do a chmod 777 on it (to give jenkins access to write log files to it):

Access Jenkins and add the build job




  • Create a new job and add a build shell with the following parameters:

cd /home/ubuntu/tests
newman -c json.postman_collection -e Prod.postman_environment -o /home/ubuntu/tests/testresults.json


  • Save and Run the build:

Comments

Popular posts from this blog

Installing Testlink (Test Management Tool) on Ubuntu 12.04 (AWS EC2) with URL Rewrite

Installing ReadyAPI on a Jenkins EC2 instance using X11