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.
Script that choose other scripts to include
I'll probably be asking many simple questions soon. :-)
Here is the first:
I am trying to write scripts which can be run on several different test environments. For this I have created separate "_include" files which I wish to be chosen at runtime. This is deterimined by setting a variable $env. I.e.
var $env_test = "url of environment";
var $env_uat = "url of environment";
var $env_stage = "url of environment";
var $env_prod = "url of environment";
var $data;
var $env = $env_prod;
function get_Script($data) {
// Production environment
if ($env = $env_prod){
$data = "C:\sahi\userdata\scripts\Functions_prod.sah";
_include($data);
}
}
I've tried several different versions of this, but the file never gets included. The closest I have gotten was to receive the error:
undefined: Mgo is not defined ("url of environment":75)
No trace available
The logs state that functions within the file I wish included are not defined. (Meaning the file was not included). I'm not much of a coder, so any help would be appreciated. What is a Mgo?
Can anyone help?
Here is the first:
I am trying to write scripts which can be run on several different test environments. For this I have created separate "_include" files which I wish to be chosen at runtime. This is deterimined by setting a variable $env. I.e.
var $env_test = "url of environment";
var $env_uat = "url of environment";
var $env_stage = "url of environment";
var $env_prod = "url of environment";
var $data;
var $env = $env_prod;
function get_Script($data) {
// Production environment
if ($env = $env_prod){
$data = "C:\sahi\userdata\scripts\Functions_prod.sah";
_include($data);
}
}
I've tried several different versions of this, but the file never gets included. The closest I have gotten was to receive the error:
undefined: Mgo is not defined ("url of environment":75)
No trace available
The logs state that functions within the file I wish included are not defined. (Meaning the file was not included). I'm not much of a coder, so any help would be appreciated. What is a Mgo?
Can anyone help?
Comments
_include includes the file during script parsing time (before execution). So you cannot use a variable there. An alternative way would be to have all the data loaded, but call the correct "load" functions based on env. If you could specify your usage, we will be able to suggest something more concrete.
Regards,
Narayan
Thanks for the quick response. My usage is just as described. I need to be able to run my scripts on different environments. These environments will have slight differences. This is why I have created a separate main functions file for each environment. I wish to have the environment under test to be chosen by changing the environment variable.
So I created main functions scripts for each environment, and a single file which lists the environments and puts them into variables. I then want to just change the environment variable to the environment I wish to test, and based on that, have the script chose which main functions script to include. There is NO data to be loaded. Just the appropriate main functions file for the particular environment.
I think your suggestion will work for me. It just means my scripts will be larger than I would have wanted - in order to address the differences between environments.
By the way, I've been using Selenium for quite some time now - Sahi is much better!!!
Regards,
Tony
I've got most of this sorted, but still have a slight problem.
Lately, all of my scripts give the following warning:
undefined: Mgo is not defined ("url under test")
No trace available
Although this does not stop me from testing, I would like to eliminate the warning if possible.
Thanks in advance.
Tony
Looks like some javascript problem in the actual application. Sahi traps errors in the actual app and logs it. Let us know if you feel this is due to Sahi itself. If you would like us to look at this, we can do a desktop sharing session to see what is going on. Email us at support@sahi.co.in for that.
Regards,
Narayan