Pre-request script

Script

PruTAN lets you to add dynamic behaviour to ISO requests. This allows you to write test suites and build requests that can contain dynamic parameters. You can add JavaScript code that executes based on events in the flow:

  • Pre-request script are executed before a request is sent to the server
  • You can add multiple functions or methods to a script for a request.
  • You can add pre-request script to both requests saved and not saved in a collection

PruTAN will then execute the script along with the requests in the specified order.

Pre-request script

Pre-request script is a piece of code that will run before the execution of request.

You can use the pre-request script for a pre-processing task such as:

  • Update body data

Writing pre-request script

If the body data of your request is in ISO format, you can utilize the xmlQuery() method along with the doc keyword to access and modify the ISO elements. The xmlQuery() method requires two inputs: the doc object and the path of the ISO element you want to update. It is important to note that the doc object should be in lowercase as it is case sensitive.

xmlUpdate(doc, '//isomsg/field[@id="0"]/@value', '900');

Examples

Let us look at an example of how you can use PruTAN to write pre-request script.

  • We will use the same request UPI > Transaction, simulated in Hostbox & executed in API module.
  • This request is simulated in Hostbox module.
  • User can explore how this request is simulated in Hostbox module for better understanding : Request
  • To get Success response, this request needs value="0200" at Field id="0" but we will execute this request with value = "0900" and using Pre-Request script it will be changed to value="0200".
  • User can see this updated request body in request payload data in browser console.
// Request body
<isomsg>
  <header/>
  <field id="0" value="0900"/>
  <!-- MTI (Message Type Identifier) for request -->
  <field id="3" value="310000"/>
  <!-- Processing Code: 310000 for UPI Debit -->
  <field id="4" value="000000010000"/>
  <!-- Transaction Amount: 100.00 (amount in cents) -->
  <field id="11" value="123456"/>
  <!-- System Trace Audit Number -->
  <field id="13" value="1229"/>
  <!-- Local Transaction Date: December 29 -->
  <field id="41" value="TERM1234"/>
  <!-- Terminal ID -->
  <field id="42" value="MERCH1234567890"/>
  <!-- Merchant ID -->
  <field id="49" value="356"/>
  <!-- Currency Code: 356 for Indian Rupees -->
</isomsg>

Setting environment variables

xmlUpdate() can be used directly for quick and convenient update body value. It can be used to better organize request code.

  • Go to the pre-request script tab and copy paste the above JavaScript code as shown below:
// Pre-request Script
xmlUpdate(doc, '//isomsg/field[@id="0"]/@value', '0200');
  • Execute the request and user can see the expected response as simulated in Hostbox module.

Pre-Request Script