18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
Passing dynamic filepath in _include()
Can we pass a variable in " _inlcude($filePath)" instead of hard coding the filepath ?
I am trying this , but the script is not getting included.
var $filePath ="C:\\Program Files\\sahi\\userdata\\scripts\\"+$ABC;
_include($filePath);
addProduct($rowProductIndex[1]);
and i am getting an exception : addProduct() does not exist, though function is there in the script.
The above code works fine when i hard code the file path.
I am trying this , but the script is not getting included.
var $filePath ="C:\\Program Files\\sahi\\userdata\\scripts\\"+$ABC;
_include($filePath);
addProduct($rowProductIndex[1]);
and i am getting an exception : addProduct() does not exist, though function is there in the script.
The above code works fine when i hard code the file path.
Comments
As of now you cannot pass dynamic paths to _include. In most cases you would not need to dynamically include files. If you specify your use case we may be able to see if there are workarounds.
Regards,
Narayan
I have to add products, for which product-specific scripts has to be run.I can't go for conditional checking because the type and number of products may vary according to the test case.
Regards,
Vikas Dewan
You should ideally be creating separate functions for each product, and calling the function based on conditions.
"I can't go for conditional checking because the type and number of products may vary according to the test case" Would you not be doing a conditional check to _include the right file?
Regards,
Narayan
Can there be any better approach because i am having around 500 products ?
My idea is to have the script name and the product name same, so i just have to concatenate the
product name with ".sah" and include it in the file path.
I did it with _readCSVFile(), its working fine.
Regards,
Vikas Dewan
I just encountered a use case for variables in _includes. We have a set of general, not project related functions, like taking screenshots or videocasts. These functions get a version number like "sahi_commons2.1". When setting up Sahi for a coworker, I symlink the common functions from the userDataDir to the sahi_commons2.1 folder so that every user can easily include what he wants by typing "_include(_userDataDir+"/sahi_commons2.1/....").
A workaroud is to let the user manually link from his project to the common functions... but the case above would be more neat. Well... I do see the problems dynamic includes bring...
Regards
Wormi
is your script still working ?
i tried these and its not working for me.
_include(_userDataPath("scripts")+"/logins.sah");
_include(_userDataDir+"/logins.sah");
or, am i making some mistake here.
Regards,
Sreekanth.
Pl. try "_dynamicInclude()" instead of "_include()"
I got that info from another thread in sahi forum. http://www.tytosoftware.com/forums/discussion/4850/need-to-pass-dynamic-values-to-_include-method#Item_6
Thanks for your reply.
But, now there is a new problem. when using _dynamicInclude, sahi is not recognizing the variables declared in those included files.
Have declared them as var $abc; in files which are included.
Should I be making use of _setGlobal to make them available in all pages ?
Regards,
Sreekanth.
its working fine for me, below is the way which i have used
Path is working fine and files are getting included.
But variables declared within the included files have some problem.
If the variables are declared like "var $abc;" they are not getting identified in including file.
if variables are initialized during declaration without using "var" like "$abc = ' '; " then its working fine.
for example,
xyz.sah is the file in which i have declared variable $abc like "var $abc;"
when i include xyz.sah in pqr.sah, sahi says $abc is not defined.
If I declare variable $abc like $abc=''; in xyz.sah everything works fine.
This change happened after I used _dynamicinclude.
Hope you understood.
Regards,
Sreekanth.