Generator¶
Use Generator object to produce unique and formatted data input. Requires Rapise 7.2+
Action Summary¶
| Action | Description |
|---|---|
| Create | Creates generator object in Spira. |
| Format | Formats string according to a template. |
| GetCurrentValue | Calculates actual value of the generator according to a template. |
| GetNextValue | Calculates next value of the generator according to a template. |
| RandomString | Generates a random alphanumeric string of a given length. |
| Reset | Set Generator Value. |
Action Detail¶
Create¶
Creates generator object in Spira. To get next value from the generator use GetNextValue. Generator object can be used by parallel tests and simultaneously by different users.
Generator.Create(name, type, value, projectNameOrId)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | Unique name of the generator. |
| type | string | Type of the generator. Supported types: increment. |
| value | string | number | Initial value of the generator. |
| projectNameOrId | string | number | Name or ID of a Spira project that should host the generator. Optional. |
Returns:
number: ID of the generator or 0 in the case of error
Format¶
Formats string according to a template.
Supported patterns:
| Pattern | Description | Example |
|---|---|---|
| # | Digit 0-9 | 3 |
| dd | Day of month (1-28) | 21 |
| mm | Month number | 10 |
| yy | 00-99 | 75 |
| yyyy | Year (1950-2000) | 1993 |
| GUID | GUID | 00eccc37-6802-9adf-22f6-b376826d73c7 |
| DAY | Mon-Sat | Fri |
| NAME | Random name | Belinda |
| BOYNAMES | Random male name | William |
| GIRLNAMES | Random female name | Olivia |
| SURNAME | Random last name | Keller |
| MONTH | Jan-Dec | Apr |
| COLOR | Color | Green |
| CAR | Car vendor | Mazda |
| STREET | Random street name | Main Street |
| STATE | State name | Arkansas |
| STATECODE | State code | AR |
| CITY | Random city name | Esmont |
| COMPANY | Random company name | Earthmark |
Generator.Format(template)
Parameters:
| Name | Type | Description |
|---|---|---|
| template | string | Template string. |
Returns:
string |
number: Value generated using a template.
GetCurrentValue¶
Calculates actual value of the generator according to a template. The template can be empty, can contain {value} placeholder or be a function.
Generator.GetCurrentValue(name, template, projectNameOrId)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | Unique name of the generator. |
| template | string | Template for the value to return. If template is empty then generated value is returned as is. If it is a string then generated value replaces placeholder {value}. Template can be a function that receives the next value and calculates the value to return. Optional, Default: "{value}". |
| projectNameOrId | string | number | Name or ID of a Spira project that hosts the generator. Optional. |
Returns:
string |
number: Actual value or null
GetNextValue¶
Calculates next value of the generator according to a template. The template can be empty, can contain {value} placeholder or be a function.
Generator.GetNextValue(name, template, projectNameOrId)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | Unique name of the generator. |
| template | string | Template for the value to return. If template is empty then generated value is returned as is. If it is a string then generated value replaces placeholder {value}. Template can be a function that receives the next value and calculates the value to return. Optional, Default: "{value}". |
| projectNameOrId | string | number | Name or ID of a Spira project that hosts the generator. Optional. |
Returns:
string |
number: Next generated value or null
RandomString¶
Generates a random alphanumeric string of a given length. Requires Rapise 8.1+
Generator.RandomString(length)
Parameters:
| Name | Type | Description |
|---|---|---|
| length | number | Length of the string to return. |
Returns:
string: Generated string.
Reset¶
Set Generator Value.
Generator.Reset(name, value, projectNameOrId)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | Unique name of the generator. |
| value | string | number | New value of the generator. |
| projectNameOrId | string | number | Name or ID of a Spira project that hosts the generator. Optional. |
Returns:
string |
number: Generator Id