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.

Writing test scripts calling other scripts with passing arguments.

bosshr1043bosshr1043 Members
edited November -1 in Sahi - Open Source
Is it possible call a Script in another Script and pass argument into the calling Script in SAHI?

Comments

  • narayannarayan Administrators
    Please look at http://sahi.co.in/w/sahi-scripting-basics and _include .
  • Thank You very much Narayan for your kind help.

    From the link you gave i am clear that we can pass a Sahi script in another Sahi script.

    Now can you please tell me that, Is it possible that we can pass arguments or variables along with the Sahi script in _include()?

    For Ex:-
    Suppose in a Sahi script for login we need 2 variables UserName and Password.

    This login script can be called in any other scripts with any combination of UserName and Password.

    So is it Possible as follows:-
    _include("includesdir/login.sah","tester1","user1");



    Thanks in Advance.
  • narayannarayan Administrators
    No bosshr1043, you cannot pass parameters via _include. You will have to create a function inside the included file and then call that function with your parameters from the other file.
    // in includesdir/login.sah
    function login($user, $password){
      // your steps ...
    }
    
    // in your other scripts
    _include("includesdir/login.sah");
    login("tester1","user1");
    
  • Hi Narayan,

    Thanks Again for your support and help.

    Can you please tell me is there any other way dat we can do the above requirement in Sahi?

    Thanks in advance.
  • narayannarayan Administrators
    Hi,

    There is one other way though it is not recommended.
    // in includesdir/login.sah
    _setValue(_textbox("username'), $user);
    _setValue(_password("password'), $pwd);
    
    // In your other script
    // Define the variables before you include the other script
    var $user = "myuser";
    var $pwd = "mypwd";
    _include("includesdir/login.sah");
    

    Not sure if this is applicable to you, but if you are trying to avoid writing functions, I would suggest that spending an hour learning functions and organizing code into functions will save you a lot of maintenance problems later.

    Regards,
    Narayan
  • Hi Narayan,

    Thanks very much for the help and support.

    I will also prefer the 1st example for using function() as suggested by you.

    Thanks.
This discussion has been closed.