Functions

Welcome to PruTAN’s Functions feature — a powerful toolkit designed to simplify the creation of dynamic, data-driven API requests.
With Functions, you can automatically generate values such as card numbers, GUIDs, timestamps, random amounts, and more, directly inside request bodies, rules, pre-request scripts, or post-response scripts.

These functions help developers and testers eliminate repetitive manual data entry, ensuring test cases are flexible, reusable, and closer to real-world data simulation.

Image 1 : API

Image 2 : IC

Overview

Functions in PruTAN are prefixed with the keyword fn. in Pre-Request Script & $ in request bodies and can be invoked anywhere in a request where dynamic data is required.
They are particularly useful for:

  • Generating unique identifiers for every request.
  • Creating dynamic timestamps and random numbers.
  • Producing realistic financial data, such as card numbers or transaction amounts.
  • Simulating user data such as names, phone numbers, and emails.

You can combine multiple functions in a single request or script to dynamically control execution logic.


Commonly Used Functions

Below are some of the most widely used and practical functions for everyday test automation scenarios in PruTAN.

1. Generate GUID

Purpose:
Generates a globally unique identifier (UUID v4).

Syntax:

fn.guid()

Example Output:

2aa4ce93-c6df-43bc-ab66-3275aa2d5b04

Usage:

res.setBody("guid", fn.guid());

2. Generate Card Number

Purpose:
Generates a random card number with optional parameters for length and BIN.

Syntax:

fn.generateCard()          // Default card
fn.generateCard(10)        // 10-digit card number
fn.generateCard(12, 3)     // 12-digit card with BIN 3

Example Output:

1234567890123456

Usage:

res.setBody("cardNumber", fn.generateCard(12, 3));

3. Generate Amount

Purpose:
Generates a random monetary amount.

Syntax:

fn.generateAmount()        // Default 5-digit amount
fn.generateAmount(4, 2)    // 4 digits + 2 decimals

Example Output:

123.45

Usage:

res.setBody("amount", fn.generateAmount(4, 2));

4. Generate Date

Purpose:
Produces a dynamic date based on format and relative offsets (e.g., -1days, +1months).

Syntax:

fn.generateDate("yyyy-MM-dd HH:mm:ss", "-1days", "+1months")

Example Output:

2025-08-31 12:24:58

Usage:

res.setBody("date", fn.generateDate("yyyy-MM-dd HH:mm:ss", "-1days", "+1months"));

5. Generate Random Number

Purpose:
Creates a random numeric string of a given length, ideal for OTPs or identifiers.

Syntax:

fn.generateRandomNumber(6)

Example Output:

570813

Usage:

res.setBody("otp", fn.generateRandomNumber(6));

6. Generate Random Mobile Number

Purpose:
Generates a random 10-digit mobile number for user or transaction data.

Syntax:

fn.generateRandomMobileNumber()

Example Output:

9657457158

Usage:

res.setBody("mobile", fn.generateRandomMobileNumber());

7. Concatenate Strings

Purpose:
Joins multiple strings together into a single value — useful for combining names, IDs, or custom text values.

Syntax:

fn.concatenate("John", "Doe")
fn.concatenate("User_", fn.generateRandomNumber(4))

Example Output:

JohnDoe
User_4583

Usage:

req.setBody("fullName", fn.concatenate("John", "Doe"));
req.setBody("userId", fn.concatenate("USR_", fn.generateRandomNumber(5)));

Using Functions in Scripts

Functions can be used not only in the request body but also within Pre-request Scripts and Rules to enhance logic.

Example:

// Pre-request example
let txnId = fn.guid();
let card = fn.generateCard(12, 4);
let amt = fn.generateAmount(3);

req.setHeader("transaction-id", txnId);
req.setBody("requestPayload", {
  cardNumber: card,
  amount: amt
});

Notes

  • Functions start with the fn. prefix and are evaluated before the request is sent.
  • You can use multiple functions in combination to create complex dynamic payloads.
  • All outputs are automatically converted to strings when inserted into request fields.
  • PruTAN executes these functions securely within your workspace environment.

Example Use Case

Scenario: Automating a payment request with random values.

{
  "guid": "{{$guid()}}",
  "cardNumber": "{{$generateCard(12, 3)}}",
  "amount": "{{$generateAmount(4, 2)}}",
  "timestamp": "{{$generateDate('yyyy-MM-dd HH:mm:ss')}}"
}
  • Within request body fields, function used with $ and not with fn prefix.

This dynamic payload ensures that each request has unique, realistic data without manual intervention.

The Functions feature in PruTAN empowers teams to create dynamic, adaptable, and data-rich test scenarios — all without external scripting tools. Whether you’re simulating payment transactions, validating workflows, or stress-testing APIs, Functions make your automation smarter and faster.


The print() function in PruTAN is used to log or display messages, variable values, or debugging information during request execution.
It helps developers and testers trace their request flow, inspect intermediate data, and validate dynamic computations.


Usage Context

The print() function can be used in multiple modules across PruTAN:

  • API Module:
    Available inside Pre-request Script and Validation sections.
    Printed output appears in the Response → Raw tab.
  • Hostbox Module:
    Used within Rules, where printed messages appear in the Analytics → Logs tab.
  • Interceptor Module:
    Supported in both Request Rule and Response Rule, with logs visible in the Analytics → Logs tab.

Example in API Module

print("Response is : " + res.getBody());
print("cartId is : " + req.getBody('cartId'));

{"cartId":"CR230","message":"Added Successfully"}

// Logs
Nov 7, 2025, 3:24:57 PM - productid is 1000
Nov 7, 2025, 3:24:57 PM - price is 85000
Nov 7, 2025, 3:24:58 PM - Response is :
{"cartId":"CR230","message":"Added Successfully"}
Nov 7, 2025, 3:24:58 PM - cartId is : null

Example in Hostbox or Interceptor Modules

You can use the print() function inside Rules to log custom information such as field values, computed data, or validation results.

print("productid is " + req.getBody('productId'));
print("price is " + req.getBody('price'));

Displayed Output (Analytics → Logs tab):

Nov 7, 2025, 3:24:57 PM - productid is 1000
Nov 7, 2025, 3:24:57 PM - price is 85000

Key Points

  • print() supports string concatenation, allowing you to include static text and dynamic variables.
  • Each printed message is timestamped and recorded for better traceability.
  • Useful for debugging rules, scripts, and dynamic function outputs across modules.

Log outputs vary by module:

API → Shown under Response (Raw)

Hostbox & Interceptor → Shown under Analytics (Logs)

By using the print() function effectively, you can trace your data transformations, validate intermediate values, and debug complex automation workflows in PruTAN.