Forum Discussion
AlexKaras
14 years agoChampion Level 3
Hi Dan,
try/catch/finally handles runtime JScript errors (like using undeclared variable, array subscript out of range, null-pointer (de)referencing, etc.). In your case there is no runtime error but the code just attempts to call the method (.Wait() ) provided by TestComplete for the object (pageloginpage) that does not exist. As the method is provided by TestComplete, it is TestComplete that handles the problem of non-existing object and it is TestComplete that posts an error message to the log.
You did not post your actual code, so I cannot correct some specific lines. But the recommended approach for the situations like this (i.e. when the target object might exist or not) is to get a reference to the object via its parent WaitWindow/WaitChild/WaitNamedChild/WaitAliasChild/WaitVCLObject/etc. method (depending on the object you are looking for and the type of the tested application) and then check the .Exists property of the returned object. See the relevant help topics (Exists, WaitWindow, etc.) for more details.
Finally, your code should look like this (untested mockup):
pageloginpage = parentObject.WaitNamedChild("pageloginpage", 500);
if (pageloginpage.Exists)
{
// actions for the login window
}
else
{
// actions for the wrong login credentials
}
Hope this will help...
try/catch/finally handles runtime JScript errors (like using undeclared variable, array subscript out of range, null-pointer (de)referencing, etc.). In your case there is no runtime error but the code just attempts to call the method (.Wait() ) provided by TestComplete for the object (pageloginpage) that does not exist. As the method is provided by TestComplete, it is TestComplete that handles the problem of non-existing object and it is TestComplete that posts an error message to the log.
You did not post your actual code, so I cannot correct some specific lines. But the recommended approach for the situations like this (i.e. when the target object might exist or not) is to get a reference to the object via its parent WaitWindow/WaitChild/WaitNamedChild/WaitAliasChild/WaitVCLObject/etc. method (depending on the object you are looking for and the type of the tested application) and then check the .Exists property of the returned object. See the relevant help topics (Exists, WaitWindow, etc.) for more details.
Finally, your code should look like this (untested mockup):
pageloginpage = parentObject.WaitNamedChild("pageloginpage", 500);
if (pageloginpage.Exists)
{
// actions for the login window
}
else
{
// actions for the wrong login credentials
}
Hope this will help...
Related Content
- 2 years ago
- 13 years ago
- 11 months ago
- 5 years ago