Log Results

Applies to ReadyAPI 3.5, last modified on January 19, 2021

ReadyAPI allows you to use Groovy scripts to log your test results, extract information about test steps that meet certain conditions, and so on.

This topic describes several ways to enable logging with the Groovy script.

Where To Use

There are several ways to run this script:


  • This sample demonstrates how to save the results of every test step in a project with an event handler. Add the following code to the TestRunListener.afterStepevent handler and run the test.


    // Replace the path with the one you need.
    // Make sure the specified folder exists.
    filePath = 'c:/work/test-results/'

    // Creating output files.
    fos = new FileOutputStream( filePath + testStepResult.testStep.label + '.txt', true )

    // Filling output files.
    pw = new PrintWriter( fos )
    testStepResult.writeTo( pw )

    // Closing the output.
  • The following sample test suite teardown script demonstrates how to log results of all test steps in failed test cases:


    for ( testCaseResult in runner.results )
        // Getting all test cases’ names from the suite.
        testCaseName = testCaseResult.getTestCase().name
        log.info testCaseName

        // Checking whether the case has failed.
        if ( testCaseResult.getStatus().toString() == 'FAIL' )
            // Logging failed cases and test steps’ resulting messages.
            log.info "$testCaseName has failed"
            for ( testStepResult in testCaseResult.getResults() )
                testStepResult.messages.each() { msg -> log.info msg }

See Also

Handling Events
Setup, TearDown, and Report Scripts
Groovy Scripts

Highlight search results