Forum Discussion

KJM_VSA's avatar
KJM_VSA
New Contributor
7 years ago

Resume test runner script after keyword test fails

For testing our website, we have designed our test cases such that they are a series of keyword tests, where every page has a corresponding keyword test. We using Excel-based DDT to read in form entry values, which are then bound to the Keyword test values, and the keyword tests are run in sequence. The sequence of keyword tests is controlled by a Test Runner JavaScript script, as such:

        eval("KeywordTests." + test + ".Run()");

The issue that arises is that when an error occurs during test execution, such as an object cannot be found, I would like for there to be the option to stop the keyword test completely and move onto the next test.

 

As far as my research into this has gone, it doesn't seem possible. Currently I am able to trap the program flow in an OnLogError event handler. From here I have tried to use the Runner.Stop() method, which seems to stop the entire test run instead of just the keyword test; as well, I have tried to surround the eval statement with a try/catch block, but it looks like Test Complete intercepts the error before it can make its way back up the call stack.

I am hoping to find an alternative solution here. I'm not sure if any of these are feasible, but would it be possible to:

 

  • Return execution flow from a keyword test called from a script, back to the script, after an error; or
  • Dynamically add Test Items to the Project object to have more fine-grained control from the test runner script; or
  • Some other idea that I haven't thought of.

The last ditch solution to this would be to write something like a bash script and call Test Execute for each of the tests, but I am hoping for a more elegant solution.

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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.  

    • KJM_VSA's avatar
      KJM_VSA
      New Contributor

      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.

      • tristaanogre's avatar
        tristaanogre
        Esteemed 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.