Loadmill
Learn moreSchedule a demo
  • Introduction
    • Loadmill - AI - Powered Solution
    • Deviceless mobile testing
      • Capturing traffic with Loadmill MITM Proxy
      • Loadmill desktop recorder
        • Generating test flows
      • Installing certificate on mobile devices
        • iOS certificate installation
        • Android certificate installation
      • Configuring proxy on mobile devices
        • iOS Wi-Fi settings
        • Android Wi-Fi settings
      • Troubleshooting
    • What is an API
      • API - Data Fetching
      • Quick examples of API requests
      • What is an API endpoint?
    • API Server Testing
      • Contract testing
      • Regression Testing
  • Quick Guide
    • Create Account
    • Download Test Composer
    • Register your first API flow
    • Running Your API Test
  • Loadmill Test Composer
    • Quickstart
    • Composer Layout
    • Filter Settings
  • Test Editor
    • Layout
    • Flows
      • Generated Flow Code
      • Test Flow editor
      • Flow Controls
      • Add CSV to Flow
      • Flow Execution
    • Steps
      • Request step
      • Code step
      • Extraction & Assertion step
      • Web Socket step
    • Extractions - Set Parameters
    • Assertions - Verify Response
    • Parameters
      • Parameter Execution Order
      • Test Suite Parameters
      • Parameters Sets
    • ⨍(⨯) FUNCTIONS
    • Postscript
      • Running Postscript
      • Accessing w/ Postscript
      • Validating Postscript
    • Login/Authentication Flow
    • Before & After Hooks
  • Load Testing
    • Load Test Editor
    • Load Testing Guide
    • Analyzing Load Test Results
    • Parameterized Load Test
    • Domain Verification
    • Configuration Files
    • Load Testing FAQs
    • Load Testing Troubleshooting
  • User Behavior Testing
    • Overview
    • Setup
    • Recording troubleshooting
    • Additional recording methods
    • Recording settings
    • How to work with Recordings
  • Auth
    • Okta SSO integration
    • API Tokens
    • Testing with CORS
    • REST API
  • Integrations
    • Loadmill Agent
    • CI integration
    • GitHub
      • CI integration
      • Data sync
    • GitLab
    • Bitbucket
    • Jira
    • New Relic
    • Slack integration
    • TestRail integration
    • Database Testing
    • Kafka Testing
    • Datadog Integration
    • ✉️Email Testing
    • Webhook Testing
    • Integrations FAQs
    • XRay
    • TestRail
    • gRPC Support
  • Collaboration
    • Collaboration
    • Teams
    • Groups & Reports
    • Test Suite Collaboration
    • Reviews
    • Shared Flows
    • Labels
  • Reporting
    • API Catalog & Coverage
      • API Catalog
        • Unique Entity ID's Mapping
        • Domain Mapping and grouping
        • Endpoints grouping
        • OpenAPI upload
      • Test Coverage
        • Generating API test coverage report
  • General
    • Billing
      • Usage report
    • Settings
      • 📈Analytics
        • Flow Run History
      • 🧳Import & Export
    • General FAQs
    • General troubleshooting
    • Comparisons
      • Loadmill vs. SoapUI
      • Loadmill vs. JMeter
      • Loadmill vs. Blazemeter
      • Loadmill vs. WebdriverIO
      • Loadmill vs. Potato
    • Miscellaneous
      • Running a Test Suite
      • Test Plan
      • API Testing troubleshooting
      • API Testing FAQs
      • Test Editor
        • API Tests - Data from CSV files
Powered by GitBook
On this page
  • Writing Postscripts
  • Accessing Postscript Extractions
  • Freedom of Coding
  • Debugging Postscript
  1. Test Editor

Postscript

Create and run various assertions by adding custom codes.

Developers are always looking for ways to make their lives easier and writing code is no different. In this section, we'll take a look at how post-request scripts (or postscripts) can help you streamline your HTTP requests. Postscripts are small pieces of code that you can use to automate parts of the request-response cycle.

Writing Postscripts

With Loadmill, writing Postscript code is as easy as writing plain javascript. The server response is stored into an identifier shown as a dollar sign ($). To access specific parameter values we would use the same method as we would when accessing an object:

const apple = {
        "genus": "Malus",
        "name": "Apple",
        "id": 6,
        "family": "Rosaceae",
        "order": "Rosales",
        ...
    }
const appleFamily = apple.family; // returns "Rosaceae"

Similarly, when receiving a server response, we would view it the same:

const response = $; //returns the complete server response
const responseProperty = response.propertyName; // or response["propertyNameavascript"]
// returns the accessed property value inside the response

Accessing Postscript Extractions

The Postscript feature is very useful when you want to use coded variables on different API requests. With this feature, you can access then throughout your automated flow. This is helpful when you need to store and use information from a previous API request in subsequent requests.

In this test case we have an API returning a list of fruits as a JSON object. From that list, we'll be extracting the name and the calories from the "Apple" object and use it on our next requests:

const apple = $.find((fruit)=>fruit.name == "Apple");
// the $ represend the whole json object
// we then use an array method to find the "Apple" object

We can now access this object and it's attributes such that:

const appleName = apple.name; // returns "Apple"
const appleCalories = apple.nutritions.calories; //returns 52

To test this out we can use the console.log method to print out appleName and appleCategories

You can now access those variables within the rest of your flow.

Freedom of Coding

Postscript is a powerful tool that gives you complete control over the API. With just a few lines of code, you can create conditions, loops and functions for your API tests. Developers find it useful because they can test their APIs the same way they would in a standard programming language.

In our previous example, we tested Fruits API to better understand the Postscript execution. We will now explore the freedom of building code from our API. Here, we'll create a new array containing all the fruits family.

const fruits = $; //returns all fruits in JSON
const fruitsFamily = [];
for(var i = 0; i<fruits.length; i++){
  if(!fruitsFamily.includes(fruits[i].family)){
     fruitsFamily.push(fruits[i].family)
  }
}

We now created a new array stored in a variable called fruitsFamily that can be accessible throughout the automated test case.

Debugging Postscript

Debugging your API with Postscript is a crucial part of building an efficient test case and solid product. Some API requests may return values that are not of the same type or may have wrong or unexpected values for various reasons.

Postscript allows you to apply logging methods inside your API request the same way you would log any message or value on the web console. It provides an easy debugging and understanding of all the logged values you're extracting or building.

Using the same example above, a new array is created by looping over the entire JSON response and extracting the fruits family and adding it to the array. To validate it we use console.log to output the result.

const fruits = $; //returns all fruits in JSON
const fruitsFamily = [];
for(var i = 0; i<fruits.length; i++){
  if(!fruitsFamily.includes(fruits[i].family)){
     fruitsFamily.push(fruits[i].family)
  }
}
console.log(fruitsFamily) //
Previous⨍(⨯) FUNCTIONSNextRunning Postscript

Last updated 2 years ago