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.

How to perform exceptional statements, if text assertion fails?

nagarnagar Members
edited June 2012 in Sahi - Open Source
Hi,

In my script, I want to verify some text messages as well as successful execution of script. If verification & execution is successful, I want to set flag as 1, if it fails, I want to set 0 as flag.

I am trying to use "try catch" method with _assertEqual() API, but it doesn't work as _assertEqual does not return anything and doesn't execute the catch(e) part.
Below is my example code:
var $flag = 1;
try
{
_click(_link("abc"));
_setvalue(_textbox("name"), "xyz");

_assertEqual("Name changed successfully.", _getText(_div("successmessage")));
$flag = 1;
}
catch(e)
{
$flag = 0;
}

It does not set flag as '0', if text assertion fails.

Please help, how to do this?

Comments

  • Hi

    as far as I know, _asserts return a boolean. Try:
    $flag=_assertEqual("Name changed successfully.", _getText(_div("successmessage")));
    _alert($flag);
    

    Regards
    Wormi
  • nagarnagar Members
    Hi Wormi,

    Yes, it returns "true" if assertion succeeds, but what if it fails? It does not return anything on failure. (This is what I observed).
  • var $flag = 0;
    try
    {
    _click(_link("abc"));
    _setvalue(_textbox("name"), "xyz");
    if(_condition(_assertEqual("Name changed successfully." ,_getText(_div("successmessage"))==true))){
    $flag = 1;
    }
    }
    catch(e)
    {
    // some message
    }
Sign In or Register to comment.