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.

Script for parameterization

SamsirsameerSamsirsameer Members
edited November -1 in Sahi - Open Source
Hi,

Can u please provide me code for the below mentioned requirement.

Requirement:
I have a login function as below
function Login($uname,$pass)
{
_setValue(_textbox("j_username"), $uname);
_setValue(_password("j_password"), $pass);
_click(_submit("Log in"));
}

Login("abc",xyz")


Please provide me the code such that the Login() function call should take the values from the text file
containing values to be passed to the functions instead of giving the values in function.
Something like Login ("Username.value", "Password.value")
Ex:
File Name: Values.txt
Contents:
UserName= abc
Password= xyz

Comments

  • Hi, u can write the code like this for parameterisation

    var $content = _readFile("D:\\sahi\\Data\\Values.txt");

    var $lines = new Array();
    $lines = $content.split("\r\n");

    for (var $i = 0; $i < $lines.length; $i++)
    {

    var $uid = new Array();
    $uid = $lines[$i].split(" ");

    Login($uid[0],$uid[1]);

    }
  • Thanks, Subrat.

    The solution provided by you is good.

    but the problem exists if we have to pass many parameters to the function (like user name, password, age, sex, ..etc). because we have to remember like $uid[0] is for user name,$uid[1] is for password, $uid[2] is for age... etc.

    Since we have these values stored in a text file , the values will look like
    sam
    pass
    23
    Male

    Can we have something to be used instead of a text file so that we can be sure of the variables to which we are passing values

    like
    userName = sam
    password = pass
    age=23
    sex=Male

    So in our functions we will pass these variables
    Login ( userName, password, age, sex)

    Because, in QTP we use .ini file for paramenterization and we store the values in this .ini file.
    We will just refer the variables defined in the .ini file and the script will take the values from that .ini file

    Any help for the above requirement is highly appreciated.

    Thanks,
    SamsirSameer.
  • narayannarayan Administrators
    Could you just not define those variables in a file and include that file using _include?
Sign In or Register to comment.