Software Testing
Do Testers have to Write Code?
A very common question that a software Testing aspirant has is… Do testers have to write code??...
Postman is a scalable API testing tool that quickly integrates into CI/CD pipeline. It started in 2012 as a side project by Abhinav Asthana to simplify API workflow in testing and development. API stands for Application Programming Interface which allows software applications to communicate with each other via API calls.
In this training course, you will learn:
With over 4 million users nowadays, Postman has become a tool of choice for the following reasons:
Being an Open Source tool, Postman can be easily downloaded. Here are the steps to install:
Step 1) Go to https://www.postman.com/downloads/ and choose your desired platform among Mac, Windows or Linux. Click Download.
Step 2) Your download is in progress message should now display on the Apps page. Once the download has completed, click on Run.
Step 3) Installation Starts
Step 4) In the next window, Signup for a Postman Account
NOTE: There are two ways to sign up for a Postman account. One is to create an own Postman account, and the other is to use a Google account. Though Postman allows users to use the tool without logging in, signing up ensures that your collection is saved and can be accessed for later use.
Step 5) Select the workspace tools you need and click Save My Preferences
Step 6) You will see the Startup Screen
Below is the Postman Workspace. Let's explore the different features of the tool!
Get requests are used to retrieve information from the given URL. There will be no changes done to the endpoint.
We will use the following URL for all examples in this tutorial
https://jsonplaceholder.typicode.com/users
In the workspace
*Note: There may be cases that Get request may be unsuccessful. It can be due to an invalid request URL or authentication is needed.
Post requests are different from Get request as there is data manipulation with the user adding data to the endpoint. Using the same data from the previous tutorial in Get request, let's now add our own user.
Step 1) Click a new tab to create a new request.
Step 2) In the new tab
Step 3) In Body,
Step 4) Copy and paste just one user result from the previous get request like below. Ensure that the code has been copied correctly with paired curly braces and brackets. Change id to 11 and name to any desired name. You can also change other details like the address.
[
{
"id": 11,
"name": "Krishna Rungta",
"username": "Bret",
"email": "This email address is being protected from spambots. You need JavaScript enabled to view it.",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
]
*Note: Post request should have the correct format to ensure that requested data will be created. It is a good practice to use Get first to check the JSON format of the request. You can use tools like https://jsonformatter.curiousconcept.com/
Step 5) Next,
Data Parameterization is one of the most useful features of Postman. Instead of creating the same requests with different data, you can use variables with parameters. These data can be from a data file or an environment variable. Parameterization helps to avoid repetition of the same tests and iterations can be used for automation testing.
Parameters are created through the use of double curly brackets: {{sample}}. Let's take a look at an example of using parameters in our previous request:
Now let's create a parameterize get request.
Step 1)
There should be no response since we have not set the source of our parameter.
Step 2) To use the parameter you need to set the environment
Step 3) In variable,
Step 4) Click close if you see the next screen
Step 5) Go back to your Get request then click send. There should now be results for your request.
*Note: Always ensure that your parameters have a source such as an environment variable or data file to avoid errors.
Postman Tests are JavaScript codes added to requests that help you verify results such as successful or failed status, comparison of expected results, etc. It usually starts with pm.test. It can be compared to asserts, verify commands available in other tools.
Let's create some basic tests for our parameterize requests from the previous lesson.
Step 1) Go to your GET user request from the previous tutorial.
The pane is auto-populated
Step 2) Now click Send. The test result should now be displayed.
Step 3) Go back to the test tab and let's add another test. This time we will compare the expected result to the actual result.
From the snippets section, click on "Response body:JSON value check". We will be checking if Leanne Graham has the userid 1.
Step 4)
pm.test("Check if user with id1 is Leanne Graham", function () {
var jsonData = pm.response.json();
pm.expect(jsonData[0].name).to.eql("Leanne Graham");
});
Step 5) Click send. There should now be two passed test results for your request.
*Note: There are different kind of tests that can be created in Postman. Try to explore the tool and see what tests will fit your needs.
Collections play an important role in organizing test suites. It can be imported and exported making it easy to share collections amongst the team. In this tutorial, we will learn how to create and execute a collection.
Let's start in creating a collection:
Step 1) Click on the New button at the top left corner of the page.
Step 2) Select Collection. Create collection window should pop up.
Step 3) Input the desired collection name and description then click create. A collection should now be created.
Step 4) Go back to the previous Get request. Click Save
Step 5)
Step 6) Postman test collection should now contain one request.
Step 7) Repeat steps 4-5 for the previous Post request so that collection will now have two requests.
There are two ways to run a collection which is the Collection Runner and Newman. Let's begin by executing the collection in Collection Runner.
Step 1) Click on the Runner button found at the top of the page next to the Import button.
Step 2) Collection Runner page should appear such as below. Following is the description of various fields
Step 3) Run your Postman Test Collection by setting up the following:
Step 4) Run Results page should be displayed after clicking the Run button. Depending on the delay, you should see the tests as they execute.
You can see how important it is that there are tests in your requests so that you can verify HTTP request status if successful and the data is created or retrieved.
Another way to run a collection is via Newman. The main differences between Newman and Collection Runner are the following:
To install Newman and run our collection from it, do the following:
Step 1) Install nodejs using this link: http://nodejs.org/download/
Step 2) Open the command line and enter
npm install -g newman
Newman should now be installed on your computer.
Step 3) Once Newman has been installed, let's go back to our Postman workspace.In the Collections box, click on the three dots. Options should now appear. Select Export.
Step 4) Choose Export Collection as Collection v2.1 (Recommended) then click Export.
Step 5) Select your desired location then click Save. It is advisable to create a specific folder for your Postman tests. A collection should now be exported to your chosen local directory.
Step 6) We will also need to export our environment. Click on the eye icon beside the environment dropdown in Global, select Download as JSON. Select your desired location then click Save. It is advisable that the environment should be in the same folder as your collection.
Step 7) Environment should now be exported to the same local directory as Collection.
Step 8) Now go back to command line and change the directory to where you have saved the collection and environment.
cd C:\Users\Asus\Desktop\Postman Tutorial
Step 9) Run your collection using this command:
newman run PostmanTestCollection.postman_collection.json -e Testing.postman_globals.json
Run results should now appear such as below.
For guide is a reference to some basic Newman codes for execution:
newman run <collection name>
newman run <collection name> -e <environment name>
newman run <collection name> -n <no.of iterations>
newman run <collection name> --data <file name> -n <no.of iterations> -e <environment name>
newman run <collection name> -d <delay time>
A very common question that a software Testing aspirant has is… Do testers have to write code??...
Vulnerability Testing Vulnerability Testing also called Vulnerability Assessment is a process of...
A recorded script can simulate a virtual user; however, a mere recording may not be enough to...
What is Accessibility Testing? Accessibility Testing is defined as a type of Software Testing...
1) Which protocols are supported by LoadRunner? As of LoadRunner 9.5 following protocols are...
Software testing is the process of verifying and validating a software application to check...