Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 3.66 KB

part2-FinalCountdown.md

File metadata and controls

75 lines (53 loc) · 3.66 KB

Final Countdown - part 2

[DO] Import the template

  1. In the Postman app, click the New+ button, tab over to Templates, and find "Intro to writing tests - with examples".
  2. Import the Intro to writing tests collection using the Run in Postman button.
  3. Observe various aspects of the collection, including the web documentation.

[DO] Learn how to use variables to pass data between requests

  1. Create a new environment (to store our data), and then use the dropdown to select this new environment.
  2. Under the Integration tests folder and Using variables sub-folder, send the request Bitcoin exchange rate and inspect the response.
  3. Review the JavaScript code under the Tests tab, and observe how to get and set variables in script areas.
  4. Send the request Echo the exchange rate, and observe how to get variables in text areas.

[DO] Run a folder

  1. Run the folder Using variables in the collection runner, and observe the execution order.
  2. Write JavaScript code under the Tests tab to establish conditional logic to terminate a collection run.
  3. Run the folder again, and observe the execution order.
let jsonData = pm.response.json();
let bitcoinRate = jsonData.bpi.USD.rate_float;

if (bitcoinRate < 8000) {
  // proceed to the next request
} else {
  // stop right there
  postman.setNextRequest(null);
}

[DO] Write code to chain a request

  1. In the ShipEngine Walkthrough collection, plan what data to extract from the response body (to pass to a subsequent request).
  2. Create an environment, and select it as your active environment.
  3. Under the Tests tab of your request, write the code to parse the response body and set an environment variable.
let jsonData = pm.response.json();
pm.environment.set("nameOfVariable", valueOfVariable);

[DO] Format a different request to use this passed data

  1. Duplicate the request Echo the exchange rate from the Intro to writing tests collection, rename the request, and drag the request into the ShipEngine Walkthrough collection.
  2. Update the data to be sent in the request Echo, and review the syntax of getting and setting variables in text vs. script areas.
  3. Using the collection runner, run the ShipEngine Walkthrough collection with your newly added request.

winter solstice art

Summary

  1. Writing advanced scripts and tests
  2. Running a collection with the collection runner
  3. Using lots and lots of variables

Concepts

  1. Advanced scripts and tests
  2. Running a collection
  3. More about variables

Additional resources

  1. Intro to writing tests - with examples template
  2. Extract data to chain requests template
  3. Postman sandbox docs
  4. Working with data files: ramen template
  5. Dynamic variables in mock servers template

Next

Continue to Part 3: Liftoff