18 January 2026:


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.

Unable to catch exception using assert api

javaGurujavaGuru Members
edited November -1 in Sahi - Open Source
Hi,
Please find the below code I am trying to execute, (Using Build: 2010-08-20)


var $myPath = "C:\\Log_201Oct23.log";

try{
_assertTrue(1==2); // or any assert API
_writeFile("TEST PASS",$myPath);
}catch(e){
_writeFile("TEST FAIL",$myPath);
}

Even though the assert fails, the control does not go into the catch block (as expected) !
Under logs I see the assertion failing in red colour.

Comments

  • I'm also seeing this in build 2010-11-03. My first assertion fails but the catch assertion (which should work) is seemingly ignored and I'm getting a red failure in the logs. Here's my code:

    try {
    _assertExists(_cell($docType, _near(_link("Type[1]"))));
    } catch (e) {
    _assertExists(_cell("*Not specified", _near(_link("Type[1]"))));
    _logException("Doc Type not found...");
    }

    Perhaps I'm missing something?

    Thanks,
    Brian
  • narayannarayan Administrators
    Hi javaGuru and Brian,

    For the user, _asserts do not throw an exception. (Sahi internally catches the assert exceptions, logs them and goes on to the next step.)

    If you want conditional behaviour, please see if use can use an "if" condition.

    Regards,
    Narayan
  • Thanks Narayan, I figured this was the case. Ifs it is...

    Brian
This discussion has been closed.