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.
Browser Functions
Hello, I am hoping that someone can provide super clear instructions on writing custom functions that must run on the browser side (aka pure javascript that uses browser API's like Image, XMLHttpRequest, FileReader, etc.) I have had nothing but inconsistent behavior with them and typically find myself resorting to using something as hideous as (because _call doesn't always work for me?):
I can't make a call directly with
The only thing I can think of (which makes no sense to me), but is referenced elsewhere in the forums is that it's an issue because I'm importing the <browser> functions from a different file. Regardless, it seems to work inconsistently and significantly hinders my ability to write reliable and maintainable scripts. Can someone either outline a foolproof method of retrieving return values from browser functions that are defined in their own file, or give me any other guidance? Or can we clean up this part of Sahi so it is more reliable?
My suspicions are that whatever is parsing the javascript passed to _call and _fetch (javascript that should be getting run on the browser side since it's calling my browser functions) is failing to parse anything correctly except trivial JS and so by the time it's executed against the browser side it's become inexecutable (maybe a dollar sign issue or something?). Is this due to me not understanding the required JS format when passing to _call and _fetch? My understanding was anything goes (anything that would run fine in a browser console, that is).
Thanks!
_eval("someFunc(" + $args + ")")
and inside of
someFunc
I'm having to set values on the global window object and then retrieve the result later in my Sahi scripts using
_fetch(window.someResultVariable)
I can't make a call directly with
_fetch(someFunc($arg1, $arg2))
like you would expect (and as documented in the API docs?), even though I have defined
<browser>
someFunc(arg1, arg2){ return arg1 + arg2; }
</browser>
.The only thing I can think of (which makes no sense to me), but is referenced elsewhere in the forums is that it's an issue because I'm importing the <browser> functions from a different file. Regardless, it seems to work inconsistently and significantly hinders my ability to write reliable and maintainable scripts. Can someone either outline a foolproof method of retrieving return values from browser functions that are defined in their own file, or give me any other guidance? Or can we clean up this part of Sahi so it is more reliable?
My suspicions are that whatever is parsing the javascript passed to _call and _fetch (javascript that should be getting run on the browser side since it's calling my browser functions) is failing to parse anything correctly except trivial JS and so by the time it's executed against the browser side it's become inexecutable (maybe a dollar sign issue or something?). Is this due to me not understanding the required JS format when passing to _call and _fetch? My understanding was anything goes (anything that would run fine in a browser console, that is).
Thanks!
Answers
Using the above, allows us to do things like the following in a Sahi script: