Forum Discussion

khoffman90's avatar
khoffman90
Contributor
12 years ago

Way to Stop error posting to Log if a script fails

Is there any way to not report the error if a script fails? Alternatively I would settle for changing the error into a warning. 

6 Replies

  • sastowe's avatar
    sastowe
    Super Contributor
    var p = Sys.WaitProcess("program", <some timeout value).Exists;



    will return a boolean.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Change your code to use the WaitProcess method (see documentation here).



    something like this:



    p = Sys.WaitProcess("program", 10000)



    if (p.Exists){



    p.Close()

    }




    Essentially, methods like WaitProcess and other WaitNNN methods, will wait the specified timeout value for the object to be recognized by TestComplete.  If it returns within that time, it will return the object itself.  If it doesn't return within the time, it returns a "stub" object with the Exists property set to false.



    This should be your methodology, actually, anytime you're doing an "exists" test.





  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I would suggest first examining the error to determine why it failed.  If it's a coding problem, keep the error.



    If, however, it's a problem being reported as a problem with the application, that indicates, to me, that your handling of such errors within your automation needs to be addressed.  I'd suggest using try/catch methodology for whatever script language you are using (available also in Keyword tests) to trap such errors and log them in whatever means you want.



    You can also build into your tests such logic with "if <error condition occurs> Log.Warning" to customize how information is logged.



    It's the difference, in short, between recording a test and playing it back... and building a test that actually is a test and not just a macro.
  • Thanks for the message back. 



    The script itself is not a test.

    In order for the tests to work correctly I must ensure that there is only one version of the application running at a time. This script basically finds out if the application is already running and if it does firstly try to close it nicely and then after a period of time terminate the application.

    I do this by finding out if the application exists in the system. Process as suggested in a different thread however most of the time it does not exist and therefor the test fails.



    i.e



    var p = Sys.Process("program");

      

    if(p.Exists){

     

    p.Close();

    }



    I get process not found.



    I have tried several different ways of doing the above.  I did also try using the try/catch methods as you suggested however may not have done so correctly as it still logged an error. I will try this again tommorrow morning. 



    Thank again















  • chicks's avatar
    chicks
    Regular Contributor
    Have you tried using the find or findchild method ?   You need to get the dummy object if the process does not exist.  Otherwise, if you are explicitly defining the object, TC will look for it and print an error if it can't find it.



    Regards,  Curt
  • Right great, I think that the WaitProcess Method is what I've been looking for but I won't be able to try it out until tomorrow morning . Thanks for your help and from now on I will use this method if I'm am testing Exists.



    Thanks