Purpose
In this assignment, you will familiarize yourself with Postman, HTTP, and REST protocols using the Postman testing framework. You will also create your first node program and commit it to GitHub. Your task will be to create a Postman collection and automate REST tests within the project. Each test should include the required assertions.
Prerequisites
- Create a free account on GitHub.
- Accept GitHub Classroom – this should have been provided to you by your instructor. Classroom Assignment0
- GitHub Classroom will clone the repository CSC3916_Assignment0 for you into your GitHub Classroom repository.
- Download an Integrated Development Environment (IDE). We recommend WebStorm or VSCode.
- Download the desktop version of Postman.
Steps
Step 1: Creating a REST Request
- Open Postman.
- Click on the ‘New’ button and select ‘Request’.
- Name your request (for instance ‘Book Search’) and select or create a new collection to store this request.
- Set the request method to ‘GET’.
- Set the request URL to
https://www.googleapis.com/books/v1/volumes?q={{book_title}}
. - In the ‘Tests’ tab, add the asserts for the request validation.
Step 2: Setting up the Environment Variable and Writing Tests
Click on the settings gear icon on the top right of Postman, then click ‘Manage Environments’.
Click ‘Add’ to create a new environment. Name your environment (for instance ‘Book Search Env’).
Create a new variable named ‘book_title’ and set the initial value to ‘Turing’.
In the Tests tab, write tests to validate the response. For instance:
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Book title or description includes Turing", function () { var jsonData = pm.response.json(); for (var i = 0; i < jsonData.items.length; i++) { if (/(turing)/i.test(jsonData.items[i].volumeInfo.title) || /(turing)/i.test(jsonData.items[i].volumeInfo.description)) { pm.environment.set("book_id", jsonData.items[i].id); break; } } });
Step 3: Chaining Requests
- Create a new request as in Step 1.
- Set the request URL to
https://www.googleapis.com/books/v1/volumes/{{book_id}}
. - Similar to Step 2, write tests to validate the response.
Step 4: Modifying googlebooks.js
Open your IDE and navigate to /utils/googlebooks.js.
Modify the method to return an object like:
{ data: response.data, status: response.status, statusText: response.statusText, headers: response.headers, requestHeader: response.config.headers }
Step 5: HTTP Headers Analysis
- Investigate the HTTP headers in the request and response from the Postman console.
- Create a new text file named
headers.txt
. - Write a brief description of each key-value pair in the HTTP headers in the request and response.
- Save the file and check it into your GitHub repository with the rest of the project.
Submission
- Create a readme.md file at the root of your GitHub repository.
- Within your Postman collection, click on the arrow next to the collection name, then select ‘Share’.
- In the Share dialog, select ‘Embed’.
- Make sure to include your environment in the share by clicking ‘Environment’ and selecting the correct one.
- Choose the ‘Markdown’ tab.
- Click ‘Copy to Clipboard’ and paste this into your
readme.md
file. - Commit and push the updated
googlebooks.js
file to your GitHub repository. - Commit and push the
headers.txt
file containing your HTTP headers analysis to your GitHub repository.
Rubric
- -10 points: homework not uploaded.
- -2 points: missing Postman button in readme.md.
- -2 points: missing check in request 1 for checking title and description in items.
- -2 points: missing ID check in request 2.
- -2 points: missing change in
utils/googlebooks.js
(adding new object). - -2 points: missing text file with request headers.
Resources
- How to write tests in Postman (YouTube Video)
- How to share a postman via run in postman markdown
- Postman Learning Center: Writing tests
- Postman Learning Center: Sharing collections
Replace “your-collection-id” with the actual ID of your collection.