Log Results

Applies to ReadyAPI 3.52, last modified on April 18, 2024

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.

Example 1 – Save results of every test step

Where to use

You can run this script as the TestRunListener.afterStep event handler.

Example

Groovy

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

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

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

// Close the output
pw.close()
fos.close()

Example 2 – Save results of all test steps in failed test cases

Where to use

As a teardown script on the test suite level.

Example

The following sample demonstrates how to log results of all test steps in all the failed test cases of the test suite:

Groovy

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

    // Check whether the case has failed
    if ( testCaseResult.getStatus().toString() == 'FAIL' )
    {
        // Log 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 Scripting Samples
Scripting

Highlight search results