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 2.0 Calling _log or accessing a DOM object from function FAILS
I've been working to try and get functions working in Sahi 2.0 but I have been unsuccessful so far. Here is a basic example:
The .sah file contents:
_include("../inc/Viking/viking.inc");
// set the login values
var $uName, $pWord;
_set($uName, "someuser");
_set($pWord, "somepw");
// call the login function and validate the return
_assertEqual(true, vikingLogin($uName, $pWord), "we failed to log in!");
viking.inc contents:
<browser>
function vikingLogin($uname, $pword)
{
var retVal = false;
var $loginObjVal = "";
// login to the app and validate the username object
// reflects the credentials we logged in with
_log("in vikingLogin()...", "info");
_setValue(_textbox("j_username"), $uname);
_setValue(_password("j_password"), $pword);
_click(_submit("Login"));
$loginObjVal = _getText(top.document.getElementById('j_id13'));
//if(_condition(_containsText($loginObjVal, $uname) == false))
//{
//_log("we failed to validate the login...", "failure");
//}
//else
//{
//_log("we logged in sucessfully", "success");
// retVal = true;
//}
//_log("out of vikingLogin()...", "info");
return retVal;
}
</browser>
For debugging purposes I have the 'if' statement commented out.
If I uncomment the _log lines the function returns null. If I try to access the DOM object 'j_id13' by any means, the function returns null.
What is the problem here? Can scheduler functions not be called from a user function?
Thanks,
-Jeff
The .sah file contents:
_include("../inc/Viking/viking.inc");
// set the login values
var $uName, $pWord;
_set($uName, "someuser");
_set($pWord, "somepw");
// call the login function and validate the return
_assertEqual(true, vikingLogin($uName, $pWord), "we failed to log in!");
viking.inc contents:
<browser>
function vikingLogin($uname, $pword)
{
var retVal = false;
var $loginObjVal = "";
// login to the app and validate the username object
// reflects the credentials we logged in with
_log("in vikingLogin()...", "info");
_setValue(_textbox("j_username"), $uname);
_setValue(_password("j_password"), $pword);
_click(_submit("Login"));
$loginObjVal = _getText(top.document.getElementById('j_id13'));
//if(_condition(_containsText($loginObjVal, $uname) == false))
//{
//_log("we failed to validate the login...", "failure");
//}
//else
//{
//_log("we logged in sucessfully", "success");
// retVal = true;
//}
//_log("out of vikingLogin()...", "info");
return retVal;
}
</browser>
For debugging purposes I have the 'if' statement commented out.
If I uncomment the _log lines the function returns null. If I try to access the DOM object 'j_id13' by any means, the function returns null.
What is the problem here? Can scheduler functions not be called from a user function?
Thanks,
-Jeff
Comments
try using
_set($loginObjVal, _getText(top.document.getElementById('j_id13')));
instead of
$loginObjVal = _getText(top.document.getElementById('j_id13'));
in your function.
Regards,
Pankaj.
Is anyone else using functions in 2.0?
Thanks,
-Jeff
<browser>
function vikingLogin($uname, $pword)
{
var retVal;
retVal = true;
_log("in vikingLogin()...", "info");
return retVal;
}
</browser>
Sahi log output:
Starting script
_setGlobal('\$uName', "qqq"); at Jan 16, 2009 4:28:03 PM
_setGlobal('\$pWord', "qqq"); at Jan 16, 2009 4:28:04 PM
in vikingLogin()... at Jan 16, 2009 4:28:04 PM
_assertEqual(true, vikingLogin("qqq", "qqq"), "we failed to log in!"); at Jan 16, 2009 4:28:04 PM
If I set retVal to 'false':
<browser>
function vikingLogin($uname, $pword)
{
var retVal;
retVal = false;
_log("in vikingLogin()...", "info");
return retVal;
}
</browser>
Sahi log output:
Starting script
_setGlobal('\$uName', "qqq"); at Jan 16, 2009 4:26:25 PM
_setGlobal('\$pWord', "qqq"); at Jan 16, 2009 4:26:25 PM
in vikingLogin()... at Jan 16, 2009 4:26:25 PM
in vikingLogin()... at Jan 16, 2009 4:26:27 PM
in vikingLogin()... at Jan 16, 2009 4:26:29 PM
in vikingLogin()... at Jan 16, 2009 4:26:31 PM
in vikingLogin()... at Jan 16, 2009 4:26:33 PM
_assertEqual(true, vikingLogin("qqq", "qqq"), "we failed to log in!"); Assertion Failed. we failed to log in! Expected:[true] Actual:[false]
The function still works but _log is called multiple times. That looks like a bug.
If I call _set() to set the value of retVal, the function returns null:
<browser>
function vikingLogin($uname, $pword)
{
var retVal;
_set(retVal, true);
_log("in vikingLogin()...", "info");
return retVal;
}
</browser>
Sahi log output:
Starting script
_setGlobal('\$uName', "qqq"); at Jan 16, 2009 4:33:12 PM
_setGlobal('\$pWord', "qqq"); at Jan 16, 2009 4:33:12 PM
_assertEqual(true, vikingLogin("qqq", "qqq"), "we failed to log in!"); TypeError: Object expected
No trace available Click for browser script at Jan 16, 2009 4:33:21 PM
FYI - prefixing the variable retVal with a '$' makes no difference.
Does anyone on the board have a suggestion or a similar experience?
Thanks,
-Jeff
I meant to reply to you earlier but somehow missed it.
You do not really need a browser function in your code.
What you really want, is to first get the value of vikingLogin into a variable and then do the assert.
The key was to keep vikingLogin out of _assertEqual since _assertEqual would have tried to execute vikingLogin on the browser, instead of in the proxy.
Any other suggestions?
Thanks.
-Jeff
Jeff, could you email me your scripts to narayan @ sahi.co.in? I will have a look at why it is failing. Could you also tell me which version of Sahi you are using?
Regards,
Narayan