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.

Return value for assertions

JaoBrJaoBr Members
edited November -1 in Sahi - Open Source
Hi Narayan.

I have another question about assertions.
Is there anyway, in the assertion, when it is a success or it fails, to make Sahi give me a response about this?
I don't know if you can understand, but its something like this:
var $test;

if(assertion is a success){
         $test = "success";
         doSomething();
}else{
         $test = "fail";
         doSomethingElse();
}

Thanks.

Comments

  • narayannarayan Administrators
    Hi JaoBr,

    What you are looking for is not an assertion, but just the outcome of a condition.

    Eg:

    if($a == 10)

    or

    if (_condition(_containsText(_div("error_msg"), "Invalid login")))

    Don't use an assertion in these places.

    An assertion checks for a condition, and throws an exception if the condition is false. This causes the script to log an error message. You should not use assert statements for conditional flow.

    Regards,
    Narayan
  • JaoBrJaoBr Members
    Oh, well, doing by this way, I was trying to do the following:
        if(_condition(_containsText(_textbox("id"), ""))){
            _log("success");
        }else{
            _log("error");
        }
        if(_condition(_containsText(_textbox("id"), "no text"))){
            _log("success");
        }else{
            _log("error");
        }
    

    But both 'if' log "error".
    Without '_condition', they log "success".

    Also tried:

    if(_condition(_textbox("\$V_Id").value == ""))

    But always throws an exception.
  • narayannarayan Administrators
    if(_condition(_textbox("\$V_Id").value == ""))

    is the correct way to do it. (_containsText is for innerText matches)

    Could you share the exception?
  • JaoBrJaoBr Members
    Here:

    _sahi.saveCondition("__lastConditionValue__0", _textbox("\$V_Id").value == "")
    TypeError: '_sahi._textbox(...).value' is null or not an object
    No trace available
    Click for browser script at 31/03/2010 13:43:06

    The system runs in an popup window, I don't know if I need to use "_popup("mysystem")", I tried, but no results.
  • narayannarayan Administrators
    JaoBr,

    _condition does not work on popups.

    You will need to do
    var $condn = false;
    _popup("mysystem")._set($condn, _textbox("\$V_Id").value == "");
    if($condn){
      _log("success");
    }else{
      _log("error");
    }
    
  • JaoBrJaoBr Members
    Yeah, that was the problem.

    Thanks :)
This discussion has been closed.