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 evaluate a boolean Conditon in IF ... ELSE loop

ootoot Members
edited November -1 in Sahi - Open Source
Hi..
I am trying to automate execution of testcase scenario where in I just want to evaluate a condition in a If ....Else loop such that I can print a success message on successful completion of that scenario or else print failure . Below is a sample code .

1)_click(_imageSubmitButton("Save"));
2)_click(_byId("validationMessageBillingEvent"));
3)_assertNotNull(_byId("validationMessageBillingEvent"));
4)_assertContainsText("Billing Event is successfully created.", _byId("validationMessageBillingEvent"));
5) If(evaluate condition){
6) _debugToFile("Billing Event is successfully created ", "D:\\abc.csv");
7) }
8) else {
9) _debugToFile("Billing Event is unsuccessfull ", "D:\\abcd.csv");
10) }

I want to use a If condition at the line (5) such that it will evaluate condition and return a boolean value so that i can write success/failure message accordingly using If Else condition.How can i do it ?
Please help me out .

Comments

  • Hi oot,

    Try this........

    _assertNotNull(_byId("validationMessageBillingEvent"));
    var $ret;
    _set($ret,_assertContainsText("Billing Event is successfully created.", _byId("validationMessageBillingEvent")));
    If($ret)
    {
    _debugToFile("Billing Event is successfully created ", "D:\\abc.csv");
    }

    else {
    _debugToFile("Billing Event is unsuccessfull ", "D:\\abcd.csv");
    }


    _assertContainsText-Returns true(boolean value) if that assert is passed
  • narayannarayan Administrators
    edited November 2008
    You could use
    if (_condition(_containsText(_byId("validationMessageBillingEvent"), "Billing Event is successfully created."))){
      _debugToFile("Billing Event is successfully created ", "D:\\abc.csv");
    }else{
      _debugToFile("Billing Event is unsuccessfull ", "D:\\abcd.csv");
    }
    
    or
    $status=false;
    _set($status, _containsText(_byId("validationMessageBillingEvent"), "Billing Event is successfully created."));
    if ($status){
      _debugToFile("Billing Event is successfully created ", "D:\\abc.csv");
    }else{
      _debugToFile("Billing Event is unsuccessfull ", "D:\\abcd.csv");
    }
    
    The last one is similar to what Priya suggests, except that _containsText is more correct than _assertContainsText.
  • ootoot Members
    Thanks a lot ... it works :-)
Sign In or Register to comment.