Forum Discussion

kenny_trytek's avatar
kenny_trytek
Occasional Contributor
14 years ago

Retrieve Error Message in Keyword Test Try...Catch Block

I understand that inside scripts, exceptions can be caught using

try

{

  //code here

}

catch (exception)

{ Log.Error(exception.message)}



However, because I am testing a Flex app, there are no native components throwing errors so the Debug Agent cannot tell the script that an error has occurred, even with "Advanced exception handling" enabled.  Exceptions are not occurring, just object errors such as "Object Not Found".



Because of this, I had replaced the script try...catch with a keyword statement try...catch.  Now the error is caught and I can insert my own error handling, but I cannot determine how to access the error message.  In scripts, the catch statement takes a parameter that contains the generated exception, but there is seemingly no equivalent in the keyword catch statement.



How can I access the generated error message in the keyword catch statement?

4 Replies


  • Hello Kenny,





    Currently, you cannot obtain the text of an exception from within a keyword test. I have added a request to implement this functionality to our database. 





    However, it is not clear what situation you are trying to handle using the Try Catch statement. What error appears during the test playback and what is the exact text of this error? Also, please describe the way you want to handle this error and send us the code snippet where the error occurs.


  • kenny_trytek's avatar
    kenny_trytek
    Occasional Contributor
    I want a test harness like this:



    function runTest(testName)

    {

        var test = KeywordTests[testName];

        Pretest_Cleanup.discardChanges();

        var docReady = Pretest_Cleanup.waitDocumentReady(30000);

        if(docReady)

        {

            Pretest_Cleanup.removeAllSectionsManually();

            Pretest_Cleanup.addNewSection();

            try

            {

              test.Run();

            }

            catch(exception)

            {

              KeywordTest.handleException(exception);

            }

        }

        

        KeywordTest.endKeywordTest(test, docReady);

        KeywordTest.logTestResult(test);

    }



    "test" is a keyword test obtained from the KeywordTests object.  KeywordTest is a class that has functions useful for manipulating keyword test results and the test itself.



    An example of an error I would want to catch and handle would be this:

    "Unable to activate the disabled control."

    Sys.Process("IEXPLORE").Page("https://wf-quality-staging-hrd.appspot.com/editor").Panel("flashContainerDiv").Object("WebFilings").WFDialog("File Manager").Button("btnOpen")



    I want to handle all errors manually, but the above script block does not catch errors related to object manipulation like the example.  I tried wrapping the entire keyword test in a try...catch block, and that was what brought about the question of retrieving the error message in the first place.  Here's a screenshot: http://screencast.com/t/a0SrRDyccPD

  • Hello Kenny,





    The "Unable to activate the disabled control." error is an error of the same kind as the "Object not found" or "Object Does Not Exist" error. These errors cannot be caught by the Try...Catch statement, because they are actually not exceptions raised by the test engine. Instead, you can handle them within the OnLogError event handler. Read the Creating an Event Handler for the OnLogError Event help topic in this relation. Does this help?