Forum Discussion
What we've done is similar to what you have implemented. In our case, what we do is use try/catch/finally logic. When a problem happens in a keyword test, we actually raise an exception. Then our runner routine has try catch logic within the loop so that, if a keyword test raises an exception, that test exits, we do some "cleanup" in the catch logic, and then go back into the loop for the next keyword test.
How do you get the keyword test to raise an exception? The Test Complete 'errors' don't seem to trigger JavaScript errors; I have an error being thrown from the onLogError handler, but the catch block in the test runner routine seems to be ignored. I have read elsewhere that if the error is raised in another unit the error will be unable to be caught. If it was the keyword test itself raising the exception, I could see that working.
- tristaanogre8 years agoEsteemed Contributor
We actually wrote a little piece of code in JavaScript that we call anytime we want to raise an exception... simply a function that looks like this:
function throwError(errorText){ Log.Error(errorText); throw Error(errorText); }
Call this as a script routine in your keyword test and it will throw the exception which will bubble up through your framework code to your handling routines.
- KJM_VSA8 years agoNew Contributor
I tried that out and it appears to work; by just throwing an error directly from the keyword test, it seems to make it back to the original eval expression.
Unfortunately, It appears that I can't get errors to propagate from the onLogError handler. If I try to throw an error from the handler, the error gets logged, but will not hit the catch block associated with the eval expression. I was hoping this could be done to catch unexpected errors such as objects not being found, halt the test and move onto the next one. I'm not sure how you could integrate this into the keyword test itself.
I appreciate your help with this.
- tristaanogre8 years agoEsteemed Contributor
Unfortunately, object not found errors don't raise as an exception. However, depending upon how your test is constructed, you can add checks after you search for an object and raise your own exception if the object is not found (if object exists, for example).