Saving the log to a disk after each test

One of the possible applications for capturing events is regular saving of the log to HDD to avoid the loss of results against unforeseen situations (blackouts, emergency TestComplete termination, and so on). This is particularly important in big projects, where there are many tests being executed and results being checked regularly.

In this recipe, we will consider how to store the log as each test completes.

How to do it...

To save the results after each test execution is over, it is necessary to perform the following steps:

  1. Create an event handle for the OnStopTest event.
  2. Place the following code into the created handler:
    Log.Event("Saving results to disk");
    Log.SaveToDisk();
  3. Create several testing functions with any contents, for example:
    function Test1()
    {
      Log.Message("Test 1");
    }
  4. Add these functions to test items (right-click on the name of the project, and navigate to Edit | Test Items). In the result, the listing of the tests will appear, as follows:
    How to do it...
  5. Launch the whole project for execution by right-clicking on the name of the project and selecting the Run menu item.

    In the result, a log will be instanced, thereby the results of each test execution will be saved to HDD (this is easy to verify by checking for the message at the end of each test):

    How to do it...

How it works...

Saving the log to HDD is possible at any given moment of time by invoking the Log.SaveToDisk method.

We are doing so at the end of each test, using the OnStopTest event. Pay attention that the event is triggered at the end of each test and launched via test items. If you simply launch the function from which you call several tests, the event will fire just once (as each invoked function completes its call), rather than upon each invoked test. For example:

function TestAll()
{
  Test1();
  Test2();
  // OnStopTest
}

See also

  • More details about adding event handlers can be read about in the Creating event handlers recipe
  • Creation of test items is thoroughly dealt with in the Creating a test plan for regular runs recipe in Chapter 4, Running Tests
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.17