Skip to content
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.Flowcharts is retired. Current docs
Get Free Trial
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.

Utility APIs

Modes BrowserWindowsJavaAndroidiOSSAP

Parameters

NameTypeDescription
$maxNumberintegermaximum number

Returns

integerRandom number between 0 and maxNumber

Sahi Pro Classic API _random

Modes BrowserWindowsJavaAndroidiOSSAP

This action helps extract specific content from strings.

Parameters

NameTypeDescription
$strstringString to find pattern in
$patternstringRegular expression as native regex (/a/) or as a string ("/a/")
$onlyGroupsbooleanoptionalif true, returns only the groups matched.

Returns

stringContent from a string if there is only one matched pattern
array of stringsArray of matched pattern from the specified string
Raw script
// Example:
// To get value "250" from "Rs. 250"
_extract("Rs. 250", "/Rs. (.*)/", true); // returns "250"
_extract("Rs. 250", "/Rs. (.*)/"); // returns an array ["Rs. 250", "250"]
// Multiple groups with and without onlyGroups
var $str = "The traffic light changed from red to green";
var $pattern = "/from (.*) to (.*)/";
var $extracted = _extract($str, $pattern);
// $extracted now has the overall match "from red to green" and the individual groups "red" and "green"
_assertEqual(["from red to green", "red", "green"], $extracted);
// Setting onlyGroups=true, we do not get back the overall match.
var $extracted = _extract($str, $pattern, true);
// $extracted now has only the individual groups "red" and "green"
_assertEqual(["red", "green"], $extracted);

Sahi Pro Classic API _extract

Modes BrowserWindowsJavaAndroidiOSSAP

Parameters

NameTypeDescription
$argstring|array of strings|two dimensional array of stringsString or 1-d or 2-d array.

Returns

stringtrimmed string if $arg is a string
array of stringstrimmed array if $arg is an array
two dimensional array of stringstrimmed 2 dimensional array if $arg is a 2 dimensional array
Raw script
var $s = " sahi pro ";
$s = _trim($s);
_assertEqual("sahi pro", $s);
var $arr = ["",,,"sahi", "pro",,,"",,];
$arr = _trim($arr);
_assertEqual("sahi", $arr[0]);
_assertEqual("pro", $arr[1]);
_assertEqual(2, $arr.length);
var $array2D = [[],[],[],["","",""],["abc", "xyz", "c"], ["1", "2", "3"], ["1", "2", "3"], ["1", "2", "3"], ["1", "2", "3"],[],[""],[]];
$array2D = _trim($array2D);
_assertEqual("xyz", $array2D[0][1]);
_assertEqual(5, $array2D.length);

Sahi Pro Classic API _trim

Modes BrowserWindowsJavaAndroidiOSSAP

It converts a JSON object to String.

Example

Parameters

NameTypeDescription
$objectJSON ObjectJSON to convert to string.

Returns

stringJSON string
Raw script
var $libObj = {
"name":"John Johnson",
"street":"Oslo West 16",
"age":33,
"phone":"555 1234567"};
// Gives string corresponding to json object.
var $jsonString = _toJSON($libObj);

Sahi Pro Classic API _toJSON

Modes BrowserWindowsJavaAndroidiOSSAP

Example

Parameters

NameTypeDescription
$passwordstringpassword to be encrypted

Returns

stringEncrypted password string
Raw script
var $pass = _encrypt("secret");
_setPassword(_password("password"), $pass);

Sahi Pro Classic API _encrypt

Modes Browser

Example

Parameters

NameTypeDescription
$windowIdentifierstringoptionalthe windowIdentifier can be the window name, the window title, the window url or a regular expression of any of these.

Returns

array of stringsArray of sessionId
Raw script
var $sessionId = _getSessionId("Sahi Start");
$sessionId = _getSessionId("/Sahi/");
$sessionId = _getSessionId("/Sahi/[0]");
$sessionId = _getSessionId();

Sahi Pro Classic API _getSessionId