Data Generator Functions
The Data Generator functions create random test data such as text, phone numbers, numbers, email addresses, dates, and booleans, for use anywhere in a script.
_generateText
Section titled “_generateText”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generateText([$prefix[, $minLength[, $maxLength[, $suffix[, $includeAlphabet[, $includeNumeric[, $includeSpecial[, $addTimestamp]]]]]]]])Arguments
| Name | Type | Description |
|---|---|---|
$prefix | stringoptional | Text to prepend to the generated value |
$minLength | integeroptional | Minimum length of the generated text |
$maxLength | integeroptional | Maximum length of the generated text |
$suffix | stringoptional | Text to append to the generated value |
$includeAlphabet | booleanoptional | If true, the generated text includes alphabet characters |
$includeNumeric | booleanoptional | If true, the generated text includes numeric characters |
$includeSpecial | booleanoptional | If true, the generated text includes special characters |
$addTimestamp | booleanoptional | If true, appends a timestamp to the generated value |
Returns
string | The generated text value |
Generates random text data based on the given parameters.
var $text = _generateText("txt_", 5, 10, "_end", true, true, false, false);_generatePhoneNumber
Section titled “_generatePhoneNumber”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generatePhoneNumber([$formats])Arguments
| Name | Type | Description |
|---|---|---|
$formats | arrayoptional | List of phone number formats to generate from, e.g. "+xx (xxx) xxx-xxxx", "xxx-xxx-xxxx" |
Returns
string | The generated phone number |
Generates a random phone number based on the given formats.
var $phone = _generatePhoneNumber(["xxx-xxx-xxxx"]);_generateNumber
Section titled “_generateNumber”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generateNumber([$prefix[, $minValue[, $maxValue[, $decimals[, $separator[, $decimalSeparator[, $suffix]]]]]]])Arguments
| Name | Type | Description |
|---|---|---|
$prefix | stringoptional | Text to prepend to the generated value |
$minValue | integeroptional | Minimum value of the generated number |
$maxValue | integeroptional | Maximum value of the generated number |
$decimals | integeroptional | Number of decimal places in the generated number |
$separator | stringoptional | Thousands separator to use in the generated number |
$decimalSeparator | stringoptional | Decimal separator to use in the generated number |
$suffix | stringoptional | Text to append to the generated value |
Returns
string | The generated number |
Generates a random number based on the given parameters.
var $number = _generateNumber("$", 1, 100, 2, ",", ".", "");_generateEmail
Section titled “_generateEmail”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generateEmail([$names[, $domains[, $excludes[, $addTimestamp]]]])Arguments
| Name | Type | Description |
|---|---|---|
$names | arrayoptional | List of names to use while generating the email address |
$domains | arrayoptional | List of domains to use while generating the email address |
$excludes | arrayoptional | List of email addresses to exclude from generation |
$addTimestamp | booleanoptional | If true, appends a timestamp to the generated email address |
Returns
string | The generated email address |
Generates a random email address based on the given parameters.
var $email = _generateEmail(["john"], ["example.com"], [], true);_generateDate
Section titled “_generateDate”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generateDate([$from[, $to[, $format]]])Arguments
| Name | Type | Description |
|---|---|---|
$from | dateoptional | From date value for the generated date |
$to | dateoptional | To date value for the generated date |
$format | stringoptional | Format to use for the generated date |
Returns
string | The generated date |
Generates a random date based on the given parameters.
var $date = _generateDate("2020-01-01", "2020-12-31", "yyyy/MM/dd");_generateBooleanValue
Section titled “_generateBooleanValue”- Since
- Sahi Pro 12.0.0.10
- Desktop Engine 12.0.0.10
- Mobile Engine 12.0.0.10
- SAP Engine 12.0.0.10
Modes BrowserWindowsJavaAndroidiOSSAP
_generateBooleanValue([$defaultValue])Arguments
| Name | Type | Description |
|---|---|---|
$defaultValue | booleanoptional | Default value to use for the generated boolean |
Returns
boolean | The generated boolean value |
Generates a random boolean value based on the given default value.
var $flag = _generateBooleanValue(true);
