Script and Suite Info Functions
_scriptName
Section titled “_scriptName”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_scriptName()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
string | Script name |
// In script D:/sahi/userdata/scripts/sahitests/check.sahvar $scriptName = _scriptName(); // returns "check.sah"_scriptPath
Section titled “_scriptPath”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_scriptPath([$fileSeparator])Arguments
| Name | Type | Description |
|---|---|---|
$fileSeparator | stringoptional | To get full script file path with specified file separator. Can be one of "\\" or "/" Defaults to "/" |
Returns
string | Full script file path |
// In script D:/sahi/userdata/scripts/sahitests/check.sahvar $_scriptPath = _scriptPath(); // returns "D:/sahi/userdata/scripts/sahitests/check.sah"var $_scriptPath = _scriptPath("\\"); // returns "D:\sahi\userdata\scripts\sahitests\check.sah"_scriptStartTime
Section titled “_scriptStartTime”- Since
- Sahi Pro 4.3
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_scriptStartTime()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Script start time as a Date object |
var $dateObj = _scriptStartTime();# Detailed usage:var $date = $dateObj.toString();var $year = $dateObj.getFullYear();var $month = $dateObj.getMonth(); // Month range 0-11var $month = $dateObj.getMonth2(); // Month range 1-12var $day = $dateObj.getDay();var $hours = $dateObj.getHours();var $minutes = $dateObj.getMinutes();var $seconds = $dateObj.getSeconds();_scriptStatus
Section titled “_scriptStatus”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_scriptStatus()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
string | 'SUCCESS' or 'FAILURE' |
_scriptInfo
Section titled “_scriptInfo”- Since
- Sahi Pro 9.2.0
- Desktop Engine 9.2.0
- Mobile Engine 9.2.0
- SAP Engine 9.2.0
Modes BrowserWindowsJavaAndroidiOSSAP
_scriptInfo()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Script object |
Returns script information as an associative array. One of the properties in the array is:
-
browserVersion: Browser version on which script is running
-
userAgent: Browser User-Agent on which script is running
var $scriptInfo = _scriptInfo();var $browserVersion = $scriptInfo["browserVersion"];// orvar $name = $scriptInfo.browserVersion;_addToScriptInfo
Section titled “_addToScriptInfo”- Since
- Sahi Pro 9.2.0
- Desktop Engine 9.2.0
- Mobile Engine 9.2.0
- SAP Engine 9.2.0
Modes BrowserWindowsJavaAndroidiOSSAP
_addToScriptInfo($customFieldName, $customFieldValue)Arguments
| Name | Type | Description |
|---|---|---|
$customFieldName | string | Name of the Custom Field. |
$customFieldValue | string | Value of the Custom Field. |
Returns
null |
Appends the customFieldName and customFieldValue in Script Info.
_addToScriptInfo("summary", "Login - Regression Testing");_userDataDir
Section titled “_userDataDir”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_userDataDir([$fileSeparator])Arguments
| Name | Type | Description |
|---|---|---|
$fileSeparator | stringoptional | To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/" |
Returns
string | Full file path of userdata directory |
$userDataPath = _userDataDir(); // returns "D:/sahi/userdata"$userDataPath = _userDataDir("\\"); // returns "D:\sahi\userdata"_userDataPath
Section titled “_userDataPath”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_userDataPath($relPath[, $fileSeparator])Arguments
| Name | Type | Description |
|---|---|---|
$relPath | string | Path to resolve relative to userdata path |
$fileSeparator | stringoptional | To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/" |
Returns
string | Full file path of file resolved relative to userdata directory |
// If you have a data/excelsheets folder in sahi/userdata folder,// you can access it using$excelDataPath = _userDataPath("data/excelsheets"); // returns "D:/sahi/userdata/data/excelsheets"$excelDataPath = _userDataPath("data/excelsheets", "\\"); // returns "D:\sahi\userdata\data\excelsheets"_resolvePath
Section titled “_resolvePath”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_resolvePath($relPath[, $fileSeparator])Arguments
| Name | Type | Description |
|---|---|---|
$relPath | string | Path to resolve relative to current script path |
$fileSeparator | stringoptional | To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/" |
Returns
string | Full file path of file resolved relative to current script path |
/*If the current script isD:/sahi/userdata/scripts/user/login.sahIf you have common csv file inD:/sahi/userdata/scripts/common/user.csv*/// using$csvPath = _resolvePath("../common/user.csv"); // returns "D:/sahi/userdata/scripts/common/user.csv"$csvPath = _resolvePath("../common/user.csv", "\\"); // returns "D:\sahi\userdata\scripts\common\user.csv"_sessionInfo
Section titled “_sessionInfo”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_sessionInfo()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Current session object |
Returns information about the current session as an associative array. The object has attributes:
- isRecording: returns true if recording
- isPlaying: returns true if playingback
- isPaused: returns true if the test run is paused
- sessionId: returns Sahi’s sessionId
- threadNumber: returns the threadNumber of browser instance running
- scriptPath: returns script path of current script. Same as _scriptPath()
var $sessionInfo = _sessionInfo();var $sessionId = $sessionInfo["sessionId"];// orvar $sessionId = $sessionInfo.sessionId;_suiteInfo
Section titled “_suiteInfo”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_suiteInfo()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Suite object |
Returns suite information as an associative array. Some of the properties in the array are:
- suiteReportId: The suite report id for the suite/script run
- suiteName: Name of suite/script
- suitePath: Path of suite/script
- baseURL: Base url for suite/script run
- browserType: Browser that the suite/script was run on
var $suiteInfo = _suiteInfo();var $name = $suiteInfo["suiteName"];// orvar $name = $suiteInfo.suiteName;_addToSuiteInfo
Section titled “_addToSuiteInfo”- Since
- Sahi Pro 6.2.0
- Desktop Engine 7.5.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_addToSuiteInfo($customFieldName, $customFieldValue)Arguments
| Name | Type | Description |
|---|---|---|
$customFieldName | string | Name of the Custom Field. |
$customFieldValue | string | Value of the Custom Field. |
Returns
null |
Appends the customFieldName and customFieldValue in Suite Info.
_addToSuiteInfo("VersionNo", "6.1.1");_testcasesInfo
Section titled “_testcasesInfo”- Since
- Sahi Pro 6.1.0
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_testcasesInfo()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
array of objects | Array of testcase-property objects of the testcases in the script that have already been executed |
A testcase-property is an associative array with the following attributes:
- id: testcase Id, Unique identifier for testcase
- description: Description for testcase
- status: Execution status of the testcase
- timeTaken: Time taken for testcase execution
var $tcs = _testcasesInfo();for(var $i=0; $i<$tcs.length; $i++){ var $tc = $tcs[$i]; _log("id = " + $tc.id + "; description = " + $tc.description + "; status = " + $tc.status + "; timeTaken = " + $tc.timeTaken + ";");}_isDataPassed
Section titled “_isDataPassed”- Since
- Sahi Pro 5.1.0
- Desktop Engine 7.0.0
- Mobile Engine 7.5.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaAndroidiOSSAP
_isDataPassed()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true if data has been passed via a dd.csv data driven suite, else false |
More details here

