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.

Storing Global variables to be used by suite of tests

gdlex4015gdlex4015 Members
edited November -1 in Sahi - Open Source
I need to be able to Store my Global Variables in an external file so it is available for my suite of tests. Could someone tell me how I can accomplish it.

Thanks

Comments

  • RobinLRandallRobinLRandall Members
    edited February 2009
    The file sahi\htdocs\spr\extensions.js can be used for Global Functions :) but Global Variables are generally frowned upon :( Use at your own risk.
    RR
  • Hi,

    Another idea can be to use _debugToFile() to store the required variable in a file and use _readFile() to read those variables from that file.
    Or you can also use the database (excel would be a simple choice) to enter and retrieve variables.

    Regards,
    Pankaj.
  • narayannarayan Administrators
    gdlex4015,

    When you say you want to "store" do you mean you have a fixed set of common static constants or do you mean being able to store and retrieve global variables within tests in a suite?

    To just keep a few constants, like say ids of controls, you can just put it in a sahi file and include it in your other scripts.
    Eg.
    constants.sah
    ----
    var $login = "Log me in";
    var $logout = "Log me out";
    ----
    
    regular_script.sah
    ----
    _include("constants.sah");
    _click(_button($login));
    // ... Do stuff
    _click(_button($logout));
    ----
    
    To store a value from one script in a suite and use it in another script in that suite, use
    _setGlobal(<key>, <value>);
    and
    _getGlobal(<key>);

    Eg.
    script1.sah
    ----
    _setGlobal("loginName", "abcd123");
    ----
    
    script2.sah
    ----
    $login = _getGlobal("loginName");
    _setValue(_textbox("login"), $login);
    ----
    
    -Narayan
Sign In or Register to comment.