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.
if statemenets that check for null or undefined are failing
Hi
All tests were run in Firefox 3.0.
Basically I only want to do some verification checks on a checkbox if and only if it exist in the DOM
This works for me in SAHI verison 20080305
However in SAHI version 20090521 I get this error:
When I test my code in the record window I do not get an error just a return value of
And in SAHI version 20091023 I get this error:
When I update my code to check for undefined it refuses to work.
Any ideas on what is going wrong here and how I can fix it? Would really love to upgrade from my 2008 version.
Cheers
Tom
All tests were run in Firefox 3.0.
Basically I only want to do some verification checks on a checkbox if and only if it exist in the DOM
This works for me in SAHI verison 20080305
$client = {
'test':'novalue',
};
if(_checkbox('clip')!==null){
if($client.clip!==undefined){
_assertTrue(_checkbox('clip').checked);
}else{
_assertFalse(_checkbox('clip').checked);
}
}
However in SAHI version 20090521 I get this error:
_assertFalse(_checkbox('clip').checked);
TypeError: _sahi._checkbox("clip") is null
()@http://10.0.100.201/_s_/spr/concat.js:2548
()@http://10.0.100.201/_s_/spr/concat.js:2548
@http://10.0.100.201/_s_/spr/concat.js:2429
Click for browser script [object Object] at Nov 3, 2009 3:25:41 PM
So it looks like the null check is getting skipped.When I test my code in the record window I do not get an error just a return value of
[object Object]
If I reverse the !==null to a ===null then I get the error so it seems to work there just not in my scripts.And in SAHI version 20091023 I get this error:
_assertFalse(_checkbox('clip').checked);
TypeError: _sahi._checkbox("clip") is undefined
()@http://10.0.100.201/_s_/spr/concat.js:2465
()@http://10.0.100.201/_s_/spr/concat.js:2465
@http://10.0.100.201/_s_/spr/concat.js:2307
Click for browser script at Nov 3, 2009 3:32:46 PM
So it has not changed from null to undefined warning.When I update my code to check for undefined it refuses to work.
if(typeof(document.getElementsByName('clip')[0])!== 'undefined'){
if($client.clip!==undefined){
_assertTrue(_checkbox('clip').checked);
}else{
_assertFalse(_checkbox('clip').checked);
}
}
Any ideas on what is going wrong here and how I can fix it? Would really love to upgrade from my 2008 version.
Cheers
Tom
Comments
When I ran the below code by setting http://sahi.co.in/demo/formTest.htm as start url, it is working fine in 20091023 release.
$client = {
'test':'novalue',
};
if(_checkbox('c1')!==null){
if($client.c1!==undefined){
_assertTrue(_checkbox('c1').checked);
}else{
_assertFalse(_checkbox('c1').checked);
}
}
Please try it, by checking and unchecking the checkbox c1 over there.
Let us know, if you still have any probs
Thanks,
Venky
Thanks for the super quick response.
You code does work how ever your scenario does not reproduce my problem. I only want to run checks on the checkbox if it exists. A checkbox named 'c1' does exist on that page better to try this code.
In 20080305 both my _asserTrue an d_assertFalse check are correctly skipped as checkbox[c] does not exist which gives this output in the logfile
however in 20091023 _asserFalse is tested and fails because checkbox[c] does not exist which give this output in the logfile
I only want to do my _asserts checks if the element exists on the page. How can I replicate the 20080305 result in the 20091023 version?
Thanks
Tom
In the RECORD window using the TEST button this returns [Assertion Failed]
while in the Playback window the scripts throw the i snot defined error same as before
The following code works for me using Sahi 20090902 and for all practical reasons should work on your version too.
I have used the API _condition within the if condition. I have changed "!==" to "!=". This code will work from within a script but will throw an error if you try it on the controller.
Please also note that _assert*** APIs cannot be used in a conditional statement as you tried in your last example. Asserts are used to assert something and if it fails, throws an exception.
Hope this helps
Cheers
dp
Just to let ya know that your solution works brilliantly.
Thanks a million for your help and that applies to Venky aswell.
Delighted to be able to use the latest and greatest version of SAHI now.
Cheers guys
Tom