Skip to content

Latest commit

Β 

History

History
309 lines (216 loc) Β· 12.3 KB

course-notes.md

File metadata and controls

309 lines (216 loc) Β· 12.3 KB

Introduction to Postman course notes

Unit 1 - Introduction to Postman

Lesson 1 - Welcome

πŸ“š - Resources

Lesson 2 - What is Postman?

πŸ’‘ - Main ideas

  • Postman is a tool that allows us to easily work with APIs.
  • Postman is used to build HTTP requests that we send to the server running the API.

Lesson 3 - How to install Postman

πŸ’‘ - Main ideas

  • There are two ways to run Postman:
    • As a standalone app or
    • Directly in the browser
  • The standalone app is available for Windows, macOS, and Linux.
  • Postman on the web works from any browser but you may need to download the Postman Desktop Agent if your requests fail.
  • DO NOT use the Google Chrome extension as this is deprecated and no longer updated.

πŸ“š - Resources

Lesson 4 - Your first request with Postman

πŸ’‘ - Main ideas

  • To use an API you need to read the API documentation. We're using Simple Books API whose documentation can be found in the resources section of this lesson below.
  • Work in Postman is organized in Workspaces.
  • A status code 200 (or any status like 2XX) indicates that the request was successful.

πŸ“š - Resources

Lesson 5 - HTTP

πŸ’‘ - Main ideas

  • The API we are using uses the HTTPS protocol.
  • HTTPS stands for Secure Hypertext Transfer Protocol.
  • HTTPS ensures that the connection is encrypted.
  • All APIs should use HTTPS.
  • From our point of view HTTP and HTTPS are the same.
  • The HTTP request message will contain:
    • URL (address)
    • Request method (GET, POST, PUT, ...)
    • Headers (User-Agent: Postman)
    • Body
  • The HTTP response message will contain:
    • Status code (200, 404, 500, ...)
    • Headers
    • Body

Lesson 6 - Postman collections and variables

πŸ’‘ - Main ideas

  • You can save requests so that you can re-use them later on.
  • All requests need to be added to a Postman collection.
  • Typically you will have a Postman collection for each API.
  • We are storing the base address of the API in a collection variable called baseUrl.
  • Our saved baseUrl will be displayed as {{baseUrl}} in the address bar.
  • Variables allow us to avoid repeating the same information.
  • Variables allow us to easily make changes.
  • A Postman variable has two states
    • INITIAL VALUE - This will be available to others if you share the collection.
    • CURRENT VALUE - This is private to you and this is the value that Postman uses.

Lesson 7 - Query parameters

πŸ’‘ - Main ideas

  • JSON is the most popular format that APIs use to send data.
  • Query parameters start after the ? in the URL.
    • example : {{baseUrl}}/books?type=fiction
  • The format is key=value
  • Muliple query parameters are delimited in the URL with an &.
    • example: foo=1&bar=2
  • Depending on the API, some query parameters can be optional or mandatory.
  • A response status 400 indicates an issue with the request data.
  • You can enable and disable parameters by clicking the checkbox associated with each key-value pair.

Lesson 8 - Assignment

  • Study the API documentation and use the limit query parameter in the /books endpoint.
  • Try out different values.
  • Can you make the API return a status code 400?

Lesson 9 - Path variables

πŸ’‘ - Main ideas

  • :bookId is a path variable in the URL.
  • This endpoint allows us to specify a value that changes all the time, depending on the book.
  • :bookId is just a placeholder and does not get sent.
  • You can use path variables in combination with query parameters (if the API accepts this).

Lesson 10 - POST request / API Authentication

πŸ’‘ - Main ideas

  • A POST request allows you to send data in the request body.
  • The endpoint for submitting orders requires authentication.
  • Some APIs/endpoints are public and require no authentication.
  • Other APIs/endpoints are private and require authentication.
  • An access token is temporary password generated by the API.
  • To send JSON, select the POST request method and from the Body select Raw and from the list JSON.

Lesson 11 - JSON format

πŸ’‘ - Main ideas

  • You need to specify valid JSON, otherwise the server won't understand your request.
  • Use double-quotes "" for strings, separate key-value pairs with a comma sign ,
  • Numbers, booleans don't need to be between quotes.
  • Postman will indicate when your JSON is invalid.

Lesson 12 - Assignment

  • Create the POST request to order a book.
  • Try ordering a book that is not in stock.

Lesson 13 - Random test data

πŸ’‘ - Main ideas

  • You can use a special type of Postman variable to generate random data
    • example: {{$randomFullName}}
  • To inspect the request body you can use the Postman console.

πŸ“š - Resources

Lesson 14 - Is Postman the right tool for me?

πŸ’‘ - Main ideas

  • Postman is a tool for dealing with APIs.
  • Postman cannot work with User Interfaces, click buttons and fill out forms.
  • Postman is not a performance testing tool.
  • Postman can be used for security testing but has not been designed for this purpose.

Lesson 15 - Viewing existing orders

πŸ’‘ - Main ideas

  • Using the GET request method on the orders endpoint will give us a list of orders.
  • Using the POST request method on the same endpoint will let us create a new order.

Lesson 16 - Assignment

  • Look at the API documentation and identify the endpoint that would allow you to see a single order.

Lesson 17 - PATCH request

πŸ’‘ - Main ideas

  • A PATCH request is typically used for updating existing data.
  • A PATCH usually does a partial update, by changing only some of the properties.

Lesson 18 - DELETE request

πŸ’‘ - Main ideas

  • A DELETE request is used for deleting data.
  • If you try to get the same data with a GET request, you will get a 404 Not Found status code.

Unit 2 - Test automation with Postman

Lesson 19 - Introduction to test automation

πŸ’‘ - Main ideas

  • In this second part of the course, our goal is to automate testing of the API.
  • So far, we have done manual testing but we want to write API tests to avoid having to manually re-test the API

Lesson 20 - Your first API tests

πŸ’‘ - Main ideas

  • We are looking at the response to understand if the API is working properly.
  • With API tests we want to avoid manually re-testing the API.
  • Tests in Postman are written in JavaScript.
  • Tests are executed ONLY after the response has arrived from the API.
  • Postman uses an assertion library called Chai.js
  • Testing the response status code is one of the easiest tests you can write.
  • When writing tests, we want to make sure the tests fail.
  • To make the assertions on a JSON response, you first need to parse it.
  • To see the contents of a JavaScript variable you can use console.log()
  • To get a property of an object, you can use this syntax: someobject.someproperty
    • alternative syntax: someobject["someproperty"]

πŸ“š - Resources

Lesson 21 - Assignment

  • Add tests for all the requests in the collection that verify the status code.

Lesson 22 - Postman variables

πŸ’‘ - Main ideas

  • Postman variables are fundamental to automating testing of the API.
  • Postman environments (environment variables) are good if you have multiple testing environments (localhost, testing, production)
  • Postman collection variables are saved in the collection.
  • Postman global variables are available to all collection in a workspace.
  • We use Postman global variables as the data we save is not that important after the execution has stopped.

πŸ“š - Resources

Lesson 23 - Extracting data from the response

πŸ’‘ - Main ideas

  • Having hardcoded values in requests can make the API tests fail if the data changes.
  • We are using the filter function available on all arrays to remove the books that are not available.
  • Always use console.log() to view the data you are trying to set as a variable.

πŸ“š - Resources

Lesson 24 - Assignment

  • Test that the book extracted from the response is of type non-fiction
  • Ensure that the test fails.

Lesson 25 - Assignment

  • Use the Postman global variable bookId in the requests "Get single book" and "Order book".
  • Write a test that verifies the stock is >0
    • use this assertion as a starting point: pm.expect(1).to.be.above(2)

Lesson 26 - Collection runner

πŸ’‘ - Main ideas

  • The Collection runner is a built-in functionality of Postman.
  • The Collection runner allows you to execute the entire collection with just one click.
  • Make sure to check (:white_check_mark:) the "Save response" box as this will allow you to inspect the response body.

Lesson 27 - Request execution order

πŸ’‘ - Main ideas

  • If you run a Postman collection, the default order is as you have it in the collection.
  • You can change that order if you use postman.setNextRequest and specify the name of the next request
  • If you wish to stop the execution prematurely, you can so so by running postman.setNextRequest(null)

πŸ“š - Resources

Lesson 28 - Postman monitors

πŸ’‘ - Main ideas

  • Creating a Postman monitor ensures that you can run a Postman collection according to a pre-defined schedule.
  • Running the collection will be handled by Postman on their infrastructure, you don't need to keep Postman open.
  • If you are not familiar with continuous integration servers like Jenkins, GitLab CI or TeamCity, this is a quick and easy way to access a Postman collection.
  • The API needs to be accessible from any network.

Lesson 29 - Newman

πŸ’‘ - Main ideas

  • Newman is a CLI tool that can take a Postman collection, run all the tests and generate a report at the end.
  • Newman does not have an interface, you need to work with it from the terminal.
  • Often Newman is installed on an integration server like Jenkins, GitLab CI or TeamCity.
  • To run Newman on your computer, you need to have Node.js installed.
  • To install newman, run the command: npm install -g newman
  • Check if newman is install with: newman --version
  • There are three ways to access a collection from Newman:
    • Export the collection as a JSON file.
    • Share with a public link.
    • Use the Postman API to get the collection.

πŸ“š - Resources

Lesson 30 - HTML reports with Newman

πŸ’‘ - Main ideas

  • htmlextra is the most popular reporter in the Postman community

πŸ“š - Resources

Lesson 31 - CI/CD overview

πŸ’‘ - Main ideas

  • Newman is particularly useful when you integrate it with a CI server.

πŸ“š - Resources