Introduction

Introduced in Rapise 7.2, the Generator is a global object designed to help you produce unique and formatted data input for your test executions. It is highly useful in scenarios where your test needs to create a new record in a system (like a new customer, lead, or incident) and requires a unique, sequential ID every time the test is run. Because it links with Spira, the Generator ensures that these values remain unique across multiple test runs and even across different users executing tests in parallel.

Additionally, the Generator object allows you to format strings with randomly generated mock data (like names, dates, colors, or cities).

Action Summary

The Generator object consists of several useful actions:

  • Create: Creates a generator object in Spira.

  • GetNextValue: Calculates and retrieves the next sequential value of the generator according to a template.

  • GetCurrentValue: Retrieves the actual current value of the generator.

  • Format: Formats a string according to a template, populating placeholders with random or specific generated data.

  • RandomString: Generates a random alphanumeric string of a given length (requires Rapise 8.1+).

  • Reset: Sets or resets the Generator to a specific value.


Generating Unique Sequential Values

To create unique sequential IDs, you use the Create and GetNextValue actions together.

1. Create the Generator

The Create action initializes the generator. If you run your test a second time and the generator already exists in Spira, Rapise will safely skip creation and use the existing one.

Parameters:

  • name: The unique name of your generator (e.g., "LeadId").

  • type: The type of generator. Currently, the built-in type is "increment".

  • value: The initial starting value (e.g., 105).

  • projectNameOrId (optional): The ID or Name of the Spira project where the generator should be stored.

2. Get the Next Value

Once created, you use GetNextValue to retrieve the next sequence.

Parameters:

  • name: The name of the generator you created (e.g., "LeadId").

  • template: A string format indicating how the value should be presented. Use {value} where you want the incremented number to appear.

  • projectNameOrId (optional): The ID or Name of the Spira project.

Usage Example (JavaScript)

// 1. Initialize the Generator in Spira
Generator.Create("LeadId", "increment", 105); 

// 2. Fetch the next sequential value using a template string
var nextVal = Generator.GetNextValue("LeadId", "Lead_{value}");

// The output string will increment upon each run, e.g.: Lead_106, Lead_107...
Tester.Message(nextVal);

Advanced Usage in JavaScript (Custom Functions)

If your generation logic requires more sophisticated string manipulation, you can pass a custom JavaScript function into GetNextValue instead of a basic template string:

var nextValue = Generator.GetNextValue("LeadId", function(value) { 
    return "Lead_ID_" + value; 
});

Tester.Message(nextValue);

Generating Random Mock Data Using Format

The Format action is a quick way to generate mock data. It evaluates a template string and replaces recognized placeholders with randomly generated characters, numbers, names, or dates.

Common Placeholders:

  • {NAME}: Random name (e.g., Belinda)

  • {BOYNAMES} / {GIRLNAMES}: Random male/female name

  • {SURNAME}: Random last name

  • {COMPANY}: Random company name

  • {CITY} / {STREET} / {STATE}: Random geographical data

  • {MONTH} / {DAY}: E.g., Apr, Fri

  • {mm} / {dd} / {yyyy}: Random month, day, or year

  • {#}: A single random digit (0-9)

  • {GUID}: A newly generated GUID

Usage Example (JavaScript)

// Generate a formatted string with a random name and date
var msg = Generator.Format("{NAME}'s birthday is on {mm}-{dd}-{yyyy}");

// Output example: "William's birthday is on 10-21-1993"
Tester.Message(msg);

Other Useful Actions

  • GetCurrentValue: If you just need to check the current value without incrementing the sequence, you can use Generator.GetCurrentValue("LeadId", "Lead_{value}").

  • Reset: Easily reset the sequence back to a default value: Generator.Reset("LeadId", 100).

  • RandomString: If you need a quick randomized alphanumeric string, you can generate one by specifying the length: Generator.RandomString(10).


Using Generator in RVL (Rapise Visual Language)

All Generator actions are fully supported natively within RVL. You can select Generator from the Object column and define your parameters directly in the grid.

  1. Add an Action row.

  2. Set the Object to Generator.

  3. Set the Action to CreateGetNextValue, or Format.

  4. Fill in the corresponding parameters (name, type, value, template) in the param name and param value columns.

  5. For GetNextValue and Format, simply add an Output column/variable to store the generated string, mapping it to a local variable. You can then pass this variable into your web, mobile, or desktop application input steps.