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.

if(_assertExists(_imageSubmitButton("id")) == true) --- not working

lawrencelawrence Members
edited November -1 in Sahi - Open Source
OS: Windows XP
Browser: IE8
Sahi Build: V 3.5

I have a common function:

function compare($value1, $value2)
{

if($value1 == $value2)
{
return true;
}
else
{
return false;
}

}

For a particular case, I need to pass the first parameter as _assertExists(_imageSubmitButton("id")) which returns true. So the code will be:

compare(_assertExists(_imageSubmitButton("id")), true);

Now the common function "compare" returns false. However the expected value is true. Any help?

Comments

  • globalwormingglobalworming Moderators
    edited September 2011
    Hi lawrence

    please refer to http://sahi.co.in/w/if-condition , you may need a _condition in you if-clause.
    Does this help?

    Regards
    Wormi

    BTW isn't your compare function a little bit superfluous? The _assert does everything your compare() does or am I missing something?
  • Hi Wormi,

    I used the below code:

    if(_condition(_assertExists(_imageSubmitButton("id")) == true))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }

    It gives 'syntax error'. What is the correct syntax here?

    The common function is just an example and a simplified one. I am using a different one in my script for some other purpose.
  • globalwormingglobalworming Moderators
    edited September 2011
    please try

    if(_condition(_exists(_imageSubmitButton("id"))))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }

    maybe

    if(_condition(_exists(_imageSubmitButton("id"))) == true)
    is working too
  • Hi lawrence,

    It should be
    if(_exists(_imageSubmitButton("id")==true)) OR
    
    if(_condition(_exists(_imageSubmitButton("id")==true)))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }
    

    Check if this solves your issue.

    Regards
    Sumitra
  • lawrencelawrence Members
    edited September 2011
    Sahi controller displayed "missing ) after condition" in the log in both the cases:

    //case 1
    if(_condition(_exists(_imageSubmitButton("gridEventTitle_ctl" + $i_modified + "_EditImage"))==true))
    {
    // do something
    }
    else
    {
    // do something
    }

    //case 2
    if(_condition(_exists(_imageSubmitButton("gridEventTitle_ctl" + $i_modified + "_EditImage"))))
    {
    // do something
    }
    else
    {
    // do something
    }
  • Sumitra wrote:
    It should be
    if(_exists(_imageSubmitButton("id")==true)) OR
    
    if(_condition(_exists(_imageSubmitButton("id")==true)))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }
    

    Check if this solves your issue.

    Hi Sumitra,

    Both the conditions returned true. Then I entered invalid "id" and expected fail/false. But the code returned pass/true
  • Hi lawrence,

    It should be:

    if(_condition(_exists(_imageSubmitButton("id"))))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }

    Regards
    Sumitra
  • endoendo Members
    Hello.
    Function below not works with if condition... made as in your example
    function isLogin() {
    if (_condition(_exists(_textbox("Login"))))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }
    }

    isLogin();
    in log: Error syntax error

    Run script with testrunner.bat

    In Sahi Controller _exists(_textbox("Login")) true.

    My workaround:
    function isLogin() {
    if (_condition(_assertExists(_textbox("Login")) == '1'))
    {
    _alert('pass');
    }
    else
    {
    _alert('fail');
    }
    }

    isLogin();

    when assertion true -- works perfect: no errors, i see _alert('pass');
    when assertion false - have AssertionFailed in log, but if condition works fine: i see _alert('fail');

    and all test marked as Failed

    Help pls, what condition is correct and will work without errors of assertion?
  • Hi endo,

    Try the following script,
    function exist($x,$y){
    if($x==$y){
    _alert("pass");
    }else{
    _alert("fail");
    }
    }
    var $a=_exists(_image("add.gif"));
    exist($a,true);
    

    This might help you.

    Regards,
    Theeran.
Sign In or Register to comment.