Sahi Pro - Logging APIs
abstract
Logging APIs allow adding additional information to playback logs.
_log
Since Sahi Pro: 3.5Since Sahi OS: 2
_log($message[, $logType[, $imagePath]])
Arguments
$message | string | Message to log |
$logType | string optional | Changes the color in which log statement is displayed. Can be one of "INFO" , "SUCCESS" , "FAILURE" ,"CUSTOM" , "CUSTOM1" , "CUSTOM2" , "CUSTOM3" ,"CUSTOM4" , "CUSTOM5" , "CUSTOM6" Defaults to "INFO" |
$imagePath | string optional | Path to image file which will be logged along with the message. Relative paths will be resolved relative to current script. Introduced since Sahi Pro 6.0.0 |
Details
_log("Current user is " + $user); // Will log as plain text
_log("Current user is " + $user, "CUSTOM1"); // Will log in a different color
_log("Current user is " + $user, "INFO", "tiger.png"); // Will also add tiger.png in logs.
_logException
Since Sahi Pro: 3.5Since Sahi OS: 2
_logException($exception)
Arguments
$exception | Exception | Exception passed to catch block |
Details
_logException is used within a catch block to log the Exception in playback logs.
The logged line will be in plain text and the script status will not be affected by this.
_logException is used within a catch block to log the Exception in playback logs.
The logged line will be in plain text and the script status will not be affected by this.
try{
_click(_link("does not exist"));
}catch($e){
_logException($e); // Logs the exception, but does not fail
}
_logExceptionAsFailure
Since Sahi Pro: 3.5Since Sahi OS: 2
_logExceptionAsFailure($exception)
Arguments
$exception | Exception | Exception passed to catch block |
Details
_logExceptionAsFailure is used within a catch block to log the Exception in playback logs.
The logged line will be in red and the script will be marked failed because of this.
_logExceptionAsFailure is used within a catch block to log the Exception in playback logs.
The logged line will be in red and the script will be marked failed because of this.
try{
_click(_link("does not exist"));
}catch($e){
_logExceptionAsFailure($e); // Logs the exception, and fails,
// and in the logs, points to the original line as source of failure.
}
_logImage
Since Sahi Pro: 6.0.0Since Sahi OS: NA
_logImage($imagePath[, $message[, $logType]])
Arguments
$imagePath | string | Path to image file which will be logged along with the message. Relative paths will be resolved relative to current script. |
$message | string optional | Message to log |
$logType | string optional | Changes the color in which log statement is displayed. Can be one of "INFO" , "SUCCESS" , "FAILURE" ,"CUSTOM" , "CUSTOM1" , "CUSTOM2" , "CUSTOM3" ,"CUSTOM4" , "CUSTOM5" , "CUSTOM6" Defaults to "INFO" |
Details
_log("../tiger.png"); // Will add the image to logs
_log("C:/tiger.png", "This is a tiger"); // Will log image along with message
_log("C:/tiger.png", "This is a tiger in custom log message", "CUSTOM1"); // Will log image with message in a different color
Masking logs
_maskLogs
Since Sahi Pro: 4.5Since Sahi OS: NA
_maskLogs([$message])
Arguments
$message | string optional | Message to print when logging this mask statement |
Details
_maskLogs tells Sahi not to display further steps in the playback logs and in the Controller.
This is used when sensitive information like password may be entered via script, but we do not want it stored/displayed anywhere
Toggled by _unmaskLogs
_maskLogs tells Sahi not to display further steps in the playback logs and in the Controller.
This is used when sensitive information like password may be entered via script, but we do not want it stored/displayed anywhere
Toggled by _unmaskLogs
_unmaskLogs
Since Sahi Pro: 4.5Since Sahi OS: NA
_unmaskLogs([$message])
Arguments
$message | string optional | Message to print when logging this unmask statement |
Details
_maskLogs tells Sahi not to display further steps in the playback logs and in the Controller.
This is used when sensitive information like password may be entered via script, but we do not want it stored/displayed anywhere
_maskLogs tells Sahi not to display further steps in the playback logs and in the Controller.
This is used when sensitive information like password may be entered via script, but we do not want it stored/displayed anywhere
Example of _maskLogs _unmaskLogs
_setValue(_textbox("user"), "test");
_maskLogs("Password Information start");
_setValue(_password("password"), "secret");
_unmaskLogs("Password Information end");
_click(_submit("Login"));
will show this in logs:
Playback Logs
Controller Playback Tab
Disable/Enable INFO logging
_disableInfoLogging
Since Sahi Pro: 4.5.2Since Sahi OS: NA
_disableInfoLogging()
Arguments
None |
Details
Disables logging of INFO (normal) steps in playback logs.
Only SUCCESS, FAILURE and CUSTOM steps are logged.
Disables logging of INFO (normal) steps in playback logs.
Only SUCCESS, FAILURE and CUSTOM steps are logged.
_enableInfoLogging
Since Sahi Pro: 4.5.2Since Sahi OS: NA
_enableInfoLogging()
Arguments
None |
Details
Enables logging of INFO (normal) steps in playback logs
which was previously disabled using
Enables logging of INFO (normal) steps in playback logs
which was previously disabled using
_disableInfoLogging
.Demarcating Test Cases
Sections of a script may need to be marked as separate testcases while viewing in logs.
For example a single script can exercise login, verifyTotal and logout, and may be considered as 3 testcases in a single script.
_testcase
Since Sahi Pro: 4.0Since Sahi OS: NA
_testcase($testcaseId, $description)
Arguments
$testcaseId | string | Unique identifier for testcase |
$description | string | Description to be shown in logs |
Details
Demarcates a testcase (a logical boundary of steps)
The logs of the above script will look like this:
Also refer to csv files as suites.
Demarcates a testcase (a logical boundary of steps)
_navigateTo("/demo/training/");
var $t = _testcase("TC_1", "Login");
$t.start();
_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_click(_submit("Login"));
$t.end();
var $t2 = _testcase("TC_2", "Add books").start(); // can be in one line also
_setValue(_textbox("q"), "2");
_setValue(_textbox("q[1]"), "1");
_setValue(_textbox("q[2]"), "1");
_click(_button("Add"));
$t2.end();
var $t3 = _testcase("TC_8", "Verify total");
$t3.start();
_assertExists(_textbox("total"));
_assert(_isVisible(_textbox("total")));
_assertEqual("1150", _textbox("total").value);
$t3.end();
The logs of the above script will look like this:
Also refer to csv files as suites.
HAR Logging
HTTP request response information summaries can be captured during playback.(HAR refers to HTTP ARchive format of storing request response information)
If enabled, a log step may look like this:
It can be enabled globally or locally.
Globally enable HAR Logging
Addhar_logging.enabled=true
in userdata.properties
Restart Sahi for this to take effect.
Locally enable HAR Logging
Locally enable or disable HAR logging inside a script using_startHarLogging()
and _stopHarLogging()
APIs._startHarLogging
Since Sahi Pro: 6.0.0Since Sahi OS: NA
_startHarLogging()
Arguments
None |
Details
Tells Sahi to start logging HTTP request/response information for all network calls in this script.
Tells Sahi to start logging HTTP request/response information for all network calls in this script.
_stopHarLogging
Since Sahi Pro: 6.0.0Since Sahi OS: NA
_stopHarLogging()
Arguments
None |
Details
Tells Sahi to stop logging HTTP request/response information for all network calls in this script.
Tells Sahi to stop logging HTTP request/response information for all network calls in this script.