You are here: Ultra Guide>Automation Web>PostmanBasics (14 Jul 2020, MiaArmstrong)Edit AttachTags
-- MiaArmstrong - 23 Jun 2020

Setup:

  1. Navigate to getpostman.com and download the correct version for your desktop configuration.

  2. Install Postman

  3. Signup or sign in with google (use your ultratesting.us email address.)

Methods:

  1. Click on Workspace at the top of the page and create a new Personal workspace.

  2. In the GET dropdown menu you are able to choose the method that you want to use. GET and POST are the most common but you can use any method in the list.

  1. For a simple test let's use a GET request. Let's put the request in to the https://jsonplaceholder.typicode.com/ website by entering the url in the field to the right of the GET dropdown. JSONPlaceholder is a free online REST service that you can use whenever you need some fake data. Let’s use the users page which has a list of data on it in json format. Enter https://jsonplaceholder.typicode.com/users and then select SEND.

You will get back the “Pretty” “JSON” but you can change the format of the returned text using the options above the text box. Pretty makes it easier to work with because you can collapse various segments.

  1. If you click on the Headers option you can see a listing of the response headers.

  1. On the right there is a status code, how long it took, and the size of the file that was returned.

  2. POST: When you are sending a POST you should click on Params button and add the Params, which is your query string. In the Body, this is what you are posting to the request and you have to see how you want to format it. You can upload a file or you can add form data, etc. When sending a post request you can add a content-type in the Headers section.

  3. For a simple test lets send a POST to https://jsonplaceholder.typicode.com/posts We are going to be adding a post to this page. In the Key Value pairs section we need to add pairs for userName, userId, title, and body. What you will get returned is the ID of the post that was simulated. This does not really add a post it just simulates adding a post to get the response from the site. Add the Key Value pairs to the body:

  1. Now you can Send, You can Send and Download if you want to download the file that comes back, or you can Save (even if you don’t Save a history will be kept of what you’ve tested. Toggle userName off since we don't need that for this query. Select Send

  1. The id will be returned in the Body (this means the test was successful!)

  2. If you want to save your test you may do so by clicking on the ellipse to the right of the query in the history. You will have to save the request to a collection or create a collection where your request will be stored.

  1. A collection is just a group of API requests where the API request can be stored and saved in a logical arrangement. Lets create a new Collection by clicking the NEW button and the clicking Collection from the modal that pops up. Name your collection. You can also add a description if you want.

  1. Click on Authorization. This is where you can store a common authentication method that is required by all your tests in this collection. Say we are testing a site with a password, this would be a good place to store that. Choosing Basic Auth from the menu will allow you to store a User Name and a Password to be used by all tests in this collection.

  1. You can also add Pre-request scripts, Tests that are common to all queries in this collection, and any Variables that are common to this collection.














PostMan notes from the Udemy training:

  • Add Params to the request URL by clicking the Params button and adding items in the key and value fields below. Checkboxes can be used to add and take away existing params. Bulk edit to copy all params and paste.

  • You can use personal access tokens or username/password combo for authorizations to test environments. You can use the header “Authorization” or you can add it to the collection in the authorization tab to use for all items in a collection.

  • Use POST and the Body tab to send data.

  • Use GET and the Params to get data.

  • URL Variable: Use a colon to add a param with a variable value. EX :userid and then you can add a value for it in the value column.

  • Collection Variable: Edit collection and add variables in the variable tab. Can use the variable name in place of the value EX {{variable}}

  • Console: Took look through exactly what was sent and received.

  • Status Test: To test if the status returned is 2xx

  • Import a Complex Request from your browser into Postman: Inspect> Network> Preserve the log>Perform request> Click on request that was sent and Copy as cURL> Go to Postman> Import> Paste Raw Text> Import - Postman will autofill everything

  • Responses: Response status (2xx is ok, 5xx server problem, 4xx user problem) Time in milliseconds, Body, Headers

  • Cookies: (technically just a header) Set Cookie instructs the browser to set a cookie. Cookie manager: lists all domains that sent the request. Postman will save all cookies. You must use the cookie manager to delete cookies.

  • Troubleshooting: Make sure there are no typos in your url. Check if the service you are calling is available. Go to the status page for that API (google it). Type the domain of IP and port of the API you are calling in your browser. Make sure you are using the right protocol (http/https). Configure Postman if using self signed certificates.

  • Saving Requests: Save a request by placing it in a collection. Collections help you organize requests. Additionally you can add documentation, tests and are useful for sharing with others. You can share a collection with others by different means: export a collection as a file/ import from a file; share a link (requires account), embed button (requires account), team sharing (requires Postman pro) (accounts will be auto-synced with postman servers)

  • Console: You can find info about Request Headers, Response Headers and the Request Body in the console. Open then console in the bottom left corner of the postman dashboard.

  • Test: commonly just a simple assertion; one request can have multiple tests; tests only run AFTER the request completes

  • Global Variables: Click the eyeball button to add or edit global variables. To access a variable use {{variable}} when you mouse over the variable you can see the value and scope. Accessing variables in scripts: postman.getGlobalVariable(“variable_key”); or postman.setGlobalVariable(“variable_key”,”variable_value”); You can also use these: postman.clearGlobalVariable(“variable_key”); to clear one global variable and postman.clearGlobalVariables(); to clear all global variables.

  • Environmental Variables: variables for a specific environment. postman.setEnvironmentalVariable(‘variable_key”, “variable_value”); etc. Similar to globals. To add environments click on the eyeball and then click the Add button in the environment section at the top.

  • Pre-request Scripts: Similar to test scripts but with no assertions. Ideal for making your requests dynamic. Usually used in combination with variables. math.random(); gives you a random number between 1 and 10. To get a larger random number parseInt(Math.random() * 10000) for generating different IDs for different trello boards for example.

Happy Testing
Topic revision: r2 - 14 Jul 2020, MiaArmstrong
© 2020 Ultranauts - 75 Broad Street, 2nd Floor, Suite 206, New York, NY 10004 - info@ultranauts.co