Script Suite Info APIs

Script Name


Parameters
None
Return Value
stringScript name

Modes Supported :
Raw Script
// In script D:/sahi/userdata/scripts/sahitests/check.sah
var $scriptName = _scriptName(); // returns "check.sah"

Sahi Pro Classic API :_scriptName


Script Path


Parameters
$fileSeparatorstring optional To get full script file path with specified file separator. Can be one of "\\" or "/" Defaults to "/"
Return Value
stringFull script file path

Modes Supported :
Raw Script
// In script D:/sahi/userdata/scripts/sahitests/check.sah
var $_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

danger In versions prior to 6.0.0, it returned a String. Scripts written before 6.0.0 will need changes.

Parameters
None
Return Value
objectScript start time as a Date object

Modes Supported :
Raw Script
var $dateObj = _scriptStartTime();
# Detailed usage:
var $date = $dateObj.toString();
var $year = $dateObj.getFullYear();
var $month = $dateObj.getMonth(); // Month range 0-11
var $month = $dateObj.getMonth2(); // Month range 1-12
var $day = $dateObj.getDay();
var $hours = $dateObj.getHours();
var $minutes = $dateObj.getMinutes();
var $seconds = $dateObj.getSeconds();

Sahi Pro Classic API :_scriptStartTime


Script Status


Parameters
None
Return Value
string 'SUCCESS' or 'FAILURE'

Modes Supported :
Raw Script

Sahi Pro Classic API :_scriptStatus


Script Info

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
  • infoNOTE: userAgent added Since Sahi Pro: 11.0.0

Parameters
None
Return Value
objectScript object

Modes Supported :
Raw Script
var $scriptInfo = _scriptInfo();
var $browserVersion = $scriptInfo["browserVersion"];
// or
var $name = $scriptInfo.browserVersion;

Sahi Pro Classic API :_scriptInfo


Add To Script Info

Appends the customFieldName and customFieldValue in Script Info.

Parameters
$customFieldNamestring Name of the Custom Field.
$customFieldValuestring Value of the Custom Field.
Return Value

Modes Supported :
Raw Script
_addToScriptInfo("summary", "Login - Regression Testing");

Sahi Pro Classic API :_addToScriptInfo


User Data Dir


Parameters
$fileSeparatorstring optional To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/"
Return Value
stringFull file path of userdata directory

Modes Supported :
Raw Script
$userDataPath = _userDataDir(); // returns "D:/sahi/userdata"
$userDataPath = _userDataDir("\\"); // returns "D:\sahi\userdata"

Sahi Pro Classic API :_userDataDir


User Data Path


Parameters
$relPathstring Path to resolve relative to userdata path
$fileSeparatorstring optional To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/"
Return Value
stringFull file path of file resolved relative to userdata directory

Modes Supported :
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


Parameters
$relPathstring Path to resolve relative to current script path
$fileSeparatorstring optional To get path with specified file separator. Can be one of "\\" or "/" Defaults to "/"
Return Value
stringFull file path of file resolved relative to current script path

Modes Supported :
Raw Script
/*
If the current script is
D:/sahi/userdata/scripts/user/login.sah
If you have common csv file in
D:/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

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
None
Return Value
objectCurrent session object

Modes Supported :
Raw Script
var $sessionInfo = _sessionInfo();
var $sessionId = $sessionInfo["sessionId"];
// or
var $sessionId = $sessionInfo.sessionId;

Sahi Pro Classic API :_sessionInfo


Suite Info

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
None
Return Value
objectSuite object

Modes Supported :
Raw Script
var $suiteInfo = _suiteInfo();
var $name = $suiteInfo["suiteName"];
// or
var $name = $suiteInfo.suiteName;

Sahi Pro Classic API :_suiteInfo


Add To Suite Info

Appends the customFieldName and customFieldValue in Suite Info.

Parameters
$customFieldNamestring Name of the Custom Field.
$customFieldValuestring Value of the Custom Field.
Return Value

Modes Supported :
Raw Script
_addToSuiteInfo("VersionNo", "6.1.1");

Sahi Pro Classic API :_addToSuiteInfo




Is Data Passed

More details here

Parameters
None
Return Value
booleantrue if data has been passed via a dd.csv data driven suite, else false

Modes Supported :
Raw Script

Sahi Pro Classic API :_isDataPassed