Script Suite Info APIs
Script Name
Section titled “Script Name”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
string | Script name |
Raw script
// In script D:/sahi/userdata/scripts/sahitests/check.sahvar $scriptName = _scriptName(); // returns "check.sah"Sahi Pro Classic API _scriptName
Script Path
Section titled “Script Path”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| 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 |
Raw script
// 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"Sahi Pro Classic API _scriptPath
Script Start Time
Section titled “Script Start Time”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Script start time as a Date object |
Raw script
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();Sahi Pro Classic API _scriptStartTime
Script Status
Section titled “Script Status”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
string | 'SUCCESS' or 'FAILURE' |
Sahi Pro Classic API _scriptStatus
Script Info
Section titled “Script Info”Modes BrowserWindowsJavaAndroidiOSSAP
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
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Script object |
Raw script
var $scriptInfo = _scriptInfo();var $browserVersion = $scriptInfo["browserVersion"];// orvar $name = $scriptInfo.browserVersion;Sahi Pro Classic API _scriptInfo
Add To Script Info
Section titled “Add To Script Info”Modes BrowserWindowsJavaAndroidiOSSAP
Appends the customFieldName and customFieldValue in Script Info.
Parameters
| Name | Type | Description |
|---|---|---|
$customFieldName | string | Name of the Custom Field. |
$customFieldValue | string | Value of the Custom Field. |
Raw script
_addToScriptInfo("summary", "Login - Regression Testing");Sahi Pro Classic API _addToScriptInfo
User Data Dir
Section titled “User Data Dir”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| 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 |
Raw script
$userDataPath = _userDataDir(); // returns "D:/sahi/userdata"$userDataPath = _userDataDir("\\"); // returns "D:\sahi\userdata"Sahi Pro Classic API _userDataDir
User Data Path
Section titled “User Data Path”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| 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 |
Raw script
// 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"Sahi Pro Classic API _userDataPath
Resolve Path
Section titled “Resolve Path”Modes BrowserWindowsJavaAndroidiOSSAP
Parameters
| 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 |
Raw script
/*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"Sahi Pro Classic API _resolvePath
Session Info
Section titled “Session Info”Modes BrowserWindowsJavaAndroidiOSSAP
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 playback 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()
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Current session object |
Raw script
var $sessionInfo = _sessionInfo();var $sessionId = $sessionInfo["sessionId"];// orvar $sessionId = $sessionInfo.sessionId;Sahi Pro Classic API _sessionInfo
Suite Info
Section titled “Suite Info”Modes BrowserWindowsJavaAndroidiOSSAP
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
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
object | Suite object |
Raw script
var $suiteInfo = _suiteInfo();var $name = $suiteInfo["suiteName"];// orvar $name = $suiteInfo.suiteName;Sahi Pro Classic API _suiteInfo
Add To Suite Info
Section titled “Add To Suite Info”Modes BrowserWindowsJavaAndroidiOSSAP
Appends the customFieldName and customFieldValue in Suite Info.
Parameters
| Name | Type | Description |
|---|---|---|
$customFieldName | string | Name of the Custom Field. |
$customFieldValue | string | Value of the Custom Field. |
Raw script
_addToSuiteInfo("VersionNo", "6.1.1");Sahi Pro Classic API _addToSuiteInfo
Testcases Info
Section titled “Testcases Info”Modes BrowserWindowsJavaAndroidiOSSAP
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
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
array of objects | Array of testcase-property objects of the testcases in the script that have already been executed |
Raw script
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 + ";");}Sahi Pro Classic API _testcasesInfo
Is Data Passed
Section titled “Is Data Passed”Modes BrowserWindowsJavaAndroidiOSSAP
More details here
Parameters
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true if data has been passed via a dd.csv data driven suite, else false |
Sahi Pro Classic API _isDataPassed

