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.
[sahi v3] using functions within _setGlobal fails
hallo,
I am migratingfrom V1 to V3 and I have found following problem
***************** DOESNT WORK IN V3, WORKS IN V1 ***********
_setGlobal("GlobalContractName","C25 " + UniqueNumber());
function UniqueNumber(){
var UniqueNumberLocal = Math.floor(Math.random()*9999999);
return UniqueNumberLocal;
}
************** ERROR MESSAGE ***************
setGlobal("GlobalContractName","C25 " + UniqueNumber());
TypeError: Object expected
No trace available
Click for browser script at May 21, 2010 10:50:04 AM
********************* WORKAROUND IN V3 ******************
_setGlobal("GlobalContractName","C25 " + Math.floor(Math.random()*9999999));
Any ideas ?
I am migratingfrom V1 to V3 and I have found following problem
***************** DOESNT WORK IN V3, WORKS IN V1 ***********
_setGlobal("GlobalContractName","C25 " + UniqueNumber());
function UniqueNumber(){
var UniqueNumberLocal = Math.floor(Math.random()*9999999);
return UniqueNumberLocal;
}
************** ERROR MESSAGE ***************
setGlobal("GlobalContractName","C25 " + UniqueNumber());
TypeError: Object expected
No trace available
Click for browser script at May 21, 2010 10:50:04 AM
********************* WORKAROUND IN V3 ******************
_setGlobal("GlobalContractName","C25 " + Math.floor(Math.random()*9999999));
Any ideas ?
This discussion has been closed.
Comments
I have found another problem, that is related to this. I am using rel. 20100321.
The following construction doesnt work
To make it work, you need to add following line before and use $var1 instead of direct function call
Lech
There were quite a few changes from Sahi V1 to V3. One of the main things was moving execution away from the browser and into the proxy. This helped solve a lot of issues with loops, ifs etc. but made the older scripts incompatible with the newer Sahi.
To explain the behaviour:
Your code:
function UniqueNumber is defined in Rhino's runtime running inside the proxy. _setGlobal("GlobalContractName","C25 " + UniqueNumber()); is converted to a string
'_setGlobal("GlobalContractName","C25 " + UniqueNumber());' and 'eval'ed on the browser (This happens for all Browser Action APIs). So UniqueNumber would not be found on the browser, and hence fail. Math.random is inbuilt in JS, so is available both on the proxy and the browser.
_setGlobal is no longer required in V3. You can just use regular variables.
Eg.
The same thing happens with
String '_setSelected(_select("locType1"), DecodeGeoType($Hashcode);' will be 'eval'ed on the browser and DecodeGeoType will not be found. There are two solutions to this.
do
or define the function within < browser > tags, in which case, the function will be made available on the browser rather than in the proxy.
Prefixing a $ basically makes values of proxy side variables available to the browser. so
$x = "abc";
_alert($x);
will become
evalOnBrowser("_alert(" + $x + ")"); (with the required quotes around $x)
You can use $ as a start of a function also, for example, you could do
This will become
evalOnBrowser('_setSelected(_select("locType1"), ' + $DecodeGeoType($Hashcode) + ');')
Hope that helps.
Regards,
Narayan
Using $myfunction($param) instead of myfunction($param),
both for function declaration and invocation
works perfectly for me in SAHI V3
Great thanks!
Lech