Forum Discussion

eykxas's avatar
eykxas
Frequent Contributor
3 months ago
Solved

Ignoring Runtime Error

Hi !

How can I ignore Runtime Errors ? 

In my project, sometimes TestComplete (or TestExecute) is a way too fast for the webapp, and when the code tried to do some thing (like toArray() on an object) obviously it cause an error.

The tricky part is that I can't use delay or wait or anything that might take time. I have a fixed window of time that I cannot exceed.

  • FindAll returns an array of the tested objects, otherwise it return an empty array, which will have a length of zero.

    Within your function, you should also check that page actually exists, so that the method FindAll works.

    Also, be careful when reassigning variables ar = ar.toArray() 

12 Replies

  • markos's avatar
    markos
    Occasional Contributor

    Are you using keyword tests or scripting?

    By "cause an error" do you mean the array did not contain the expected elements? Or that the test crashed with an unhandled exception?

    • eykxas's avatar
      eykxas
      Frequent Contributor

      I'm using scripts. In these scripts there is often the FindAll method, which returns an array in safe format. So I have to call the toArray() method the get the array in native format, then I can sorting it.

      The problem is, if the FindAll method found nothing, it returns a stub object, and calling toArray() cause an error. Which is normal, the method doesn't exist for stub object.

      I can't find any way to secure this array, so I would like to ingore the error.

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Are you able to provide an example of your code, with the FindAll and toArray() ?

  • eykxas's avatar
    eykxas
    Frequent Contributor

    I'm not using Aliases. Plus, if I use them, there will be an auto-timeout.

    • eykxas's avatar
      eykxas
      Frequent Contributor

      The TC forum messed up the code, so I post an image instead.

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Change your code, do so something like this

        function getElement_global(...)
        {
            var objects = page.FindAll(prop, value, level, refresh);
            if (objects.length > 0) {
                var ar = objects.toArray();
                ...
            } else {
                // objects is null
            }
        }

        You need to check the returned value of FindAll, in this case the length. Anything greater than zero, implies that it has returned something. 

        Also, the code that calls this function needs to deal with null value too.