18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
force script end
I'm investigating the usage of the asserts and the callbacks.
Suppose I have an assert that fails, flow goes to onScriptFailure, but I want to end the script at that point, (don't want it to try to go on), what do I do to force the script to end?
Thanks,
Glenn
Suppose I have an assert that fails, flow goes to onScriptFailure, but I want to end the script at that point, (don't want it to try to go on), what do I do to force the script to end?
Thanks,
Glenn
Comments
you could throw an exeption in onScriptFailure, catch it and then use logExceptionAsFailure() to stop the script.
Regards
Wormi
Guess I must have done something wrong with this one. I tried to just use the _logExceptionAsFailure() as suggested, but I'm still not terminating. Here is the script so that you can see what I'm doing (in the case you can see what I'm doing wrong right away and don't have to read thru the rest
_log(_eval("navigator.userAgent"), "info");
_setValue(_textbox("uname"), "testuser000");
_setValue(_password("pword"), "123456");
_click(_radio("rb_tkper"));
_click(_submit("Log In"));
try {
_assertNotExists(_submit("Log In"), "ERROR: did not log in");
} catch (e) {
_logExceptionAsFailure(e);
}
_log("test if got here", "info");
FYI, I tried putting the try/catch logExceptionAsFailure in the onScriptFailure function.. don't do that, endless loop
So I'm hoping that I can find an API that will completely stop execution of the script. However, when I'm running the script above, I'm still executing a log statement that I put after the try/catch; ie it's not stopping execution when I call the logExceptionAsFailure. See output below:
Starting script
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19 at Apr 11, 2012 11:19:40 AM
_log(_eval("navigator.userAgent"), "info"); at Apr 11, 2012 11:19:40 AM
_setValue(_textbox("uname"), "testuser000"); at Apr 11, 2012 11:19:40 AM
_setValue(_password("pword"), "123456"); at Apr 11, 2012 11:19:40 AM
_click(_radio("rb_tkper")); at Apr 11, 2012 11:19:40 AM
_click(_submit("Log In")); at Apr 11, 2012 11:19:40 AM
_assertNotExists(_submit("Log In"), "ERROR: did not log in");
Assertion Failed. ERROR: did not log in at Apr 11, 2012 11:19:50 AM
test if got here at Apr 11, 2012 11:19:52 AM
_log("test if got here", "info"); at Apr 11, 2012 11:19:52 AM
Stopping script
Thanks for taking the time to look at this.
Regards,
Glenn
try to put this in you onScriptFailure()
Could produce a loop too, but I think it's worth a try^^
Here's the script:
function onScriptFailure(){
_log(">> In onScriptFailure..ERROR", "error");
try {
throw "Something failed";
} catch (e) {
_logExceptionAsFailure(e);
}
}
_setValue(_textbox("uname"), "testuser00000");
_setValue(_password("pword"), "123456");
_click(_radio("rb_tkper"));
_click(_submit("Log In"));
_assertNotExists(_submit("Log In"), _sessionInfo().sessionId);
_assertNotExists(_submit("Log In"), "ERROR: did not log in correctly");
_log("should not be here", "info");
_click(_link("2012-04-06"));
Here's the output:
Starting script
_setValue(_textbox("uname"), "testuser00000"); at Apr 12, 2012 7:12:47 AM
_setValue(_password("pword"), "123456"); at Apr 12, 2012 7:12:47 AM
_click(_radio("rb_tkper")); at Apr 12, 2012 7:12:47 AM
_click(_submit("Log In")); at Apr 12, 2012 7:12:47 AM
_assertNotExists(_submit("Log In"), _sessionInfo().sessionId);
Assertion Failed. sahi_cca9d15f08309040e9080d30d3c9ada00d8f at Apr 12, 2012 7:12:58 AM
>> In onScriptFailure..ERROR at Apr 12, 2012 7:13:00 AM
_log(">> In onScriptFailure..ERROR", "error"); at Apr 12, 2012 7:13:00 AM
Logging exception:
Something failed at Apr 12, 2012 7:13:00 AM
_assertNotExists(_submit("Log In"), "ERROR: did not log in correctly");
Assertion Failed. ERROR: did not log in correctly at Apr 12, 2012 7:13:10 AM
>> In onScriptFailure..ERROR at Apr 12, 2012 7:13:12 AM
_log(">> In onScriptFailure..ERROR", "error"); at Apr 12, 2012 7:13:12 AM
Logging exception:
Something failed at Apr 12, 2012 7:13:12 AM
should not be here at Apr 12, 2012 7:13:12 AM
_log("should not be here", "info"); at Apr 12, 2012 7:13:12 AM
_click(_link("2012-04-06"));
Error: The parameter passed to _click was not found on the browser at Apr 12, 2012 7:13:22 AM
Stopping script
Finally failed on the click link. So I guess as long as I send it a link that doesn't exist, I can get it to break.. but I was looking for something more elegant (but will settle for whatever works
Thanks for trying.
Kind Regards,
Glenn
i tried:
Method A:
try {
_assertNotExists(_submit("Log In"), "ERROR: did not log in");
} catch (e) {
_logExceptionAsFailure(e);
}
_log("test if got here", "info");
function onScriptFailure($e){
throw "Failed on Script Failure";
}
Method B:
onScriptFailure = onScriptError;
_assertNotExists(_submit("Log In"), "ERROR: did not log in");
_log("test if got here", "info");
function onScriptError($e){
_logExceptionAsFailure($e);
}
All the method above doesn't stop the script. Any idea/solution/workaround?
Use onScriptError to throw something and the testrunner will catch it, execute a tearDown if you like and then the execution is finished
Where is the testRunner.js located at?
I though we run the testrunner.bat instead of testRunner.js?
Thanks.
you have to create that file somewhere and _include() it.
to get a data driven feeling with this one, or just to add some parameters, refer to http://wiredworm.blogspot.de/2012/05/page-objects.html
Thanks for your workaround. I'm looking into this workaround.
But, Just would like to know if Sahi is going to look into this issue as i think a lot of users are using assert in their Automation also.
Thanks.