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.

Sahi Out Parameters.

muralimurali Members
edited November -1 in Sahi - Open Source
Hi Team,

I have a scenario like, the test case takes two parameters and sends at-least one OUT parameter, where this OUT parameter again becomes the IN parameter for another test case.

In Sahi terms:

The first Sahi script takes 2 parameters and the output should be atleast one OUT parameter, wherein, this OUT parameter becomes the IN parameter for another Sahi script.

Does Sahi support this type of approach? if so, it would be great if anyone help me how to do it with Sahi with example.

Cheers,
Murali.

Comments

  • narayannarayan Administrators
    Murali,

    Sahi does not have a concept of passing parameters to scripts.

    If script A includes script B, any variable declared in the global scope of script A is available to script B, as they are all part of the same runtime.

    Eg.
    Script_A:
    -----------
    var $a = 10;
    _include("Script_B");
    _alert($b);
    
    
    Script_B:
    -----------
    _alert($a);
    var $b = $a + 10;
    

    will work as if it was all one script
    var $a = 10;
    _alert($a);
    var $b = $a + 10;
    _alert($b);
    

    So you can just declare variables and use them.

    That said, it is highly recommended NOT to use global variables like this, because it will limit the reuse of scripts, since one script becomes tied to another.

    Instead, do this:

    1) Let included files only have functions in them. Let us call them lib1.sah and lib2.sah.
    2) Include lib1.sah and lib2.sah wherever you want and call the functions in them. That way you can mix and match various functions to get your desired result.


    So instead of having
    login.sah
    -----------
    _setValue(_textbox("u"), "u1");
    _setValue(_password("p"), "p1");
    _click(_submit("Login"));
    var $accountId;
    _set($accountId, _getText(_div("accId")));
    
    
    logout.sah
    -------------
    _click(_link("Logout"));
    
    
    changeNickname.sah
    --------------------------
    _include("login.sah");
    
    _click(_link("Edit " + $accountId)); // this is defined in login.sah
    _setValue(_textbox("nickname"), "KK");
    _click(_button("Save"));
    
    _include("logout.sah");
    


    You should do something like this:
    lib.js
    ------
    function login($username, $password){
      _setValue(_textbox("u"), $username);
      _setValue(_password("p"), $password);
      _click(_submit("Login"));
    }
    
    
    function getAccountId(){
      var $tmp;
      _set($tmp, _getText(_div("accId")));
      return $tmp;
    }
    
    function changeNickName($accId, $nickname){
      _click(_link("Edit " + $accountId));
      _setValue(_textbox("nickname"), "KK");
      _click(_button("Save"));
    }
    
    function logout(){
      _click(_link("Logout"));
    }
    
    changeNickname.sah
    --------------------------
    _include("lib.sah");
    
    login("u1", "p1");
    var $accountId = getAccountId();
    changeNickName($accountId, "KK");
    logout();
    
    


    Let me know if this makes sense to you.


    Regards,
    Narayan
  • Thank you Narayan, yes - this does make sense to me.

    I have also posted another question regarding invoking the sahi script from java program. Can you help me in discussing that senario?
Sign In or Register to comment.