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.
V2 - can functions be called to fill parameters in function calls
Hi,
I wrote a lot of scripts for sahi using pre V2 sahi controller. I just upgrated to V2 and the scripts don't work! I've tracked the issue down to how functions are called/referenced in the test scripts
An example script -
Starting script
This used to work before - and I've got about 200 scripts to change if I can't do this any more!!
John
I wrote a lot of scripts for sahi using pre V2 sahi controller. I just upgrated to V2 and the scripts don't work! I've tracked the issue down to how functions are called/referenced in the test scripts
An example script -
function returnValue()
{
return 'wibble';
}
var $tmp = returnValue();
_log( $tmp );
_log( returnValue() );
When I execute this the first _log() call succeeds and the second one fails stating that returnValue is not defined. The actual output is:Starting script
wibble
_log( "wibble" );
_log( returnValue() ); ReferenceError: returnValue is not defined
()@http://www.XX.com/_s_/spr/concat.js:2286
()@http://www.XX.com/_s_/spr/concat.js:2286
@http://www.XX.com/_s_/spr/concat.js:2193
Stopping script
Does anyone have any idea of what is going on? It looks like you can no longer call functions to fill parameters to other function calls.This used to work before - and I've got about 200 scripts to change if I can't do this any more!!
John
Comments
It may have something to do with the <browser></browser> tags that need to be put around your function. But I think they are needed only when the function is doing something on the page's DOM objects. Anyways you can just give it a try.
Go through this: http://sahi.co.in/w/scripting-changes-in-sahi-v2
Regards,
Pankaj.
1) the script fails with missing parameter errors 2) on the command line for the server, an exception is thrown any ideas?
Its hard to comment without looking at the code right now. Just check once that you have not missed passing any parameter in some function call or I think you might have called a function with some extra parameter (more than required number). Check out if something is wrong at line number #30 of setup2.sah
All the best.
Pankaj.
In Sahi V2 the script executes in the proxy, but those steps which use scheduler functions execute on the browser.
Sahi does this by first parsing your script and then "scheduling" some steps for the browser.
In your case
when parsed, becomes In the last two steps, notice how the steps in your original script have been modified to become strings and are being scheduled. The browser will pick these strings from the proxy and eval them.
The line "var $tmp = returnValue();" is executed in the proxy and since returnValue() is defined just above, it works fine.
The line "_log( returnValue() );" becomes "_sahi.schedule("_sahi._log( returnValue() );", "D:\\sahi_v2\\bin\\..\\scripts\\_1.sah&n=9");", and the string "_sahi._log( returnValue() );" will be evaled on the browser. But the browser does not have "returnValue() " defined. You can make something available to the browser by wrapping them in <browser></browser> tags.
To make your code work, you have to have another returnValue() function defined within browser tags.
Thanks for the detailed response.
For the code example I provided the <browser> tags do work. I tried the same approach in my test scripts but I was still getting the same error.
I did some more digging about and discovered that if the function is defined in a separate file the code fails
e.g. If we continue to use the trivial code example and extend it over an include file with the function definitions and a main file giving:
In the main the 'test script' we include this file -
the output of this is
To verfiy this was the root cause of the issue I'm seeing I tried copying the helper functions into the same script as the main test - the test executed correctly.
Do you have any recommendations? It will not be manageable for me to copy all my helper functions into all my test scripts.
Thanks for your continued support
John
I'll test the fix for ya!