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.

Facing problem with assertions and if statement

sumeetsvaidyasumeetsvaidya Members
edited November -1 in Sahi - Open Source
Hello Everybody,

I am facing one scenario where I am currently stuck and I need help from you guys. The scenario is as mentioned below. There is a login page with username and password text boxes.

Script steps:
1. Enter correct username
2. Enter incorrect password
3. Click Login button
4. Step 4 verifies that if logout is present then login is succesful and click logout and if logout is not present then means login failed

I tried using assertions as condition in if statement but it didn't worked (later on I found on forum that we should not assertions). To make matter verse the logout button is present on a popup.

So I am not able to figure out a way for this scenario.

Thanks in advance,
Sumeet

Comments

  • Well I found a solution which is a work around for the given problem. The bad part is that assertions in Sahi dont return any value if they fail, so had to use error handling to handle the scenario which I mentioned below.

    So this post is finally dead, hence closing it!!!


    Regards,
    Sumeet
  • narayannarayan Administrators
    Hi Sumeet,

    Don't use assertions and error handling in this case.

    An example script for you would be
    _setValue(_textbox("username"), "userOne");
    _setValue(_textbox("password"), "secret");
    _click(_button("Login"));
    
    // Get logout link exists on popup page:
    var $logoutExists = false;
    _popup("mypopup")._set($logoutExists, _exists(_link("Logout"))); 
    if ($logoutExists) { 
      // Your true statements
    } else {
      // Your false statements
    }
    

    Regards,
    Narayan
  • Hello Narayan,

    Thanks for the script. Well I have one question, is it mandatory to make use of _set() api in order to assign value of a condition (in my case it is _isvisible()). As I found that when I used an assignment operation (=) the value was not assigned.

    Below is the script which I used before using the _set api

    var $val=false;
    $val = _exists(_link("About Google"));

    but $val retained its value of false, later when I used _set() api things worked.

    Kindly let me know, is this as per design?

    Regards,
    Sumeet
  • narayannarayan Administrators
    Hi Sumeet,

    Yes _set is required in this case (till the next release).

    The reason is that the script executes in the Proxy and _set helps fetch values from the browser to the proxy.

    Regards,
    Narayan
  • Thats cool.... Narayan

    Nice enhancement ( I meant fix :) )

    Regards,
    sumeet
Sign In or Register to comment.