Results 1 to 6 of 6
  1. #1

    Error handling from Driver script

    We have Driver scripts running independent scripts overnight on a daily basis. The driver scripts are run in batch mode, and ideally if one independent script fails (e.g. "Test1"), the driver script should continue with the next one.

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">'Driver script
    Sub Main()
    Run &quot;Test1&quot;
    Run &quot;Test2&quot;
    Run &quot;Testn&quot;
    End Sub</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">OK, if we do not do any error handling, and one script fails in batch mode, then the entire driver script will terminate. The only working solution I have found so far is to put the error handling in the called scripts (i.e. "Test1", "Test2"... "Testn").

    As I inherited from other testers hundreds of scripts without any error handling, I do not want to modify all those. On the other hand, there are only about a dozen driver scripts, so that would be a good place to implement error handling.

    Now, here is an important thing: the scripts are called by the Run method, and as far as I see, if errors are not handled in those scripts, they will be delegated up to the running environment (VBA), and it will either pop up a Runtime error window, or terminate the execution (if runs in batch mode)&mdash;either way, the error will not be delegated back to the driver script. Is there any way to work around this?

  2. #2
    Senior Member
    Join Date
    Sep 2004
    Toronto, Canada

    Re: Error handling from Driver script

    I don't think adding error handling to all those scripts is as bad as you think. I believe you only have to create one error handling routine in a shared module of the Common project, and then for each script, go add the appropriate "On Error" code to the begining of the Main Sub. It might take you a while to go in and add all these lines, but it would save you lots of trouble in the long run.

    Do a search on error handling as there are lots of items posted in this forum on it.

    OK, another alternative is to create another script running in the background that acts as a watchdog for popup messages from TestPartner or VB saying that there is a runtime error, and it clicks the appropriate button to handle the dialog. I've experimented with this in the past, and I think running 2 TestPartner scripts at the same time is a bit flaky, especially if your trying to act upon TestPartner or VB error dialogs. I think testpartner freezes running the scripts until the dialog is dismissed (but I'm not 100% sure). You might want to find another scripting program that allows you to do this. Check out AutoIT as an example http://www.autoitscript.com/autoit3 . It's one of many free scripting programs out there that can interact with windows and such. Pretty easy to learn too.

    Anyway, some food for thought.

    Current AUT running test scripts on TP 6.3 build 183, SQL 2000 DB.
    Legacy AUT running on TP 5.6.0 Build 81 and TP 6.2 build 449 with SQL 2000 DB.

    Test Environment:
    TP/IE Clients on VMWare ESX 4.1 server, AUT Servers on VMWare ESX 3.5 server.

    Application Under Test (AUT):
    Client/Server based, IE 7/8 interface with SQL 2005/2008 DB.

    Automating with TP since August 2004.

  3. #3

    Re: Error handling from Driver script

    Here is what I have done for my automation suite

    Every drive script will have following lines in main sub

    ' Error Objects
    Dim GlobalErrorObject As TOnError

    'Error Objects Initialisation
    Set AppErrorObject = OnError("GlobalErrHndlr")

    GlobalErrHndlr is a function in a shared module that takes appropriate steps like logging error and taking screen shots etc.

    Recovery is slightly difficult and depends upon the application and context when the error occured.
    GlobalErrHndlr function will return some thing like

    Function GlobalErrHndlr () As tpOnErrorType

    GlobalErrHndlr = tpRetry ' or tpNextError or tpResumeNext

    End function

    Hope this helps

    Shrini Kulkarni
    Test Consultant

  4. #4

    Re: Error handling from Driver script


    Here's a "quick and dirty" solution that may satisfy your needs: If you call each script from within a sinlge batch file, using the following syntax, they will all run, one at a time, without any error handling, and best of all, if any script fails, the subsequent script will run anyway:

    tp -u &lt;username&gt; -p &lt;password&gt; -d &lt;DSN&gt; -r &lt;project_name&gt; -s &lt;1st_script_name&gt; -i
    tp -u &lt;username&gt; -p &lt;password&gt; -d &lt;DSN&gt; -r &lt;project_name&gt; -s &lt;2nd_script_name&gt; -i
    tp -u &lt;username&gt; -p &lt;password&gt; -d &lt;DSN&gt; -r &lt;project_name&gt; -s &lt;3rd_script_name&gt; -i
    tp -u &lt;username&gt; -p &lt;password&gt; -d &lt;DSN&gt; -r &lt;project_name&gt; -s &lt;4th_script_name&gt; -i

    &lt;DSN&gt; is the DSN of your TestPartner database.

    -i increments the log (the same as using "Auto Increment = True" in Tools &gt; Options &gt; Playback &gt; Logging).

    I recommend creating a new TestPartner user that only has "Executor" access for running these scripts via the command line invocation of TestPartner. That way, when browsing your logs, you can quickly identify which runs were done via the batch file just by looking at the "Last Modified By" column in the Log Browser. (And you won't be hard-coding your personal TestPartner password in the syntax shown above.)

    You can optionally call this .bat file with a Windows Scheduler Task - to run the scripts unattended.

    (Control Panel &gt; Scheduled Tasks &gt; Add Scheduled Tasks)
    Mike Davis

    If my employer's opinions differ from those I express here, let it be understood in advance that they are right and I am wrong.

  5. #5

    Re: Error handling from Driver script

    Great info! I'm implementing your 'quick and dirty' solution and it's great. However, I have to manually open each TP log to see the results. When I have 70+ or more scripts, opening each log can be very time-consuming.

    Any suggestion on how to 'quick and dirty' verify the overall status of each script?

    Thanks - Andy

  6. #6

    Re: Error handling from Driver script

    Andy, probably the only way to do that is implement your own logging solution... something that is done by very many people because TPs logging is not very useful.

    I have a global object "logger" that is called at various points in all my scripts, it writes everything to common log files.

    (p.s. i have spent a lot of time trying to implement what Tibor wants to happen, and have concluded it's not possible. The best compromise is aracknid &amp; shrini's suggestions).



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:52 PM.

Copyright BetaSoft Inc.