Forum Discussion

Finan's avatar
Finan
Frequent Contributor
14 years ago

[Resolved] Access results from testSuite.teardownscript

Hi,

I want to access results at the teardownscript of a testsuite.

In a testcase teardownscript I'd use :
for (result in testRunner.getResults())
{
log.info result.getStatus()
}


However, on testSuite level, this returns a "no such property testRunner for testSuite"
How do I fix this?
  • Finan's avatar
    Finan
    Frequent Contributor
    I changed the script into the following:
    import com.eviware.soapui.impl.wsdl.panels.support.MockTestRunner

    int count = testSuite.getTestCaseCount()
    for(i = 0; i < count; i++)
    {
    testCase = testSuite.getTestCaseAt(i)
    testRunner = new MockTestRunner(testCase)
    for (result in testRunner.getResults())
    {
    log.info result.getStatus()
    }
    }

    But this doesn't return anything:(
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    From the TestSuite scope, the test runner is referenced as runner, whereas it's referenced as testRunner in the TestCase scope. The naming discrepancy is because of legacy reasons. We should change this in the future (I've added it to our backlog).


    Tips: The available variables in a script is always shown in the upper right corner:


    Regards!

    /Henrik
    eviware.com
  • Finan's avatar
    Finan
    Frequent Contributor
    ah ok, that explains it a bit.....


    so on the testSuite.tearDownScript level the following script returns the results from each testCase:
    for(result in runner.results)
    {
    log.info result.getStatus()
    }


    1. In case a testCase has failed, I'd like to know which testStep has failed. How do I script this?
    2. For each testCase that returns a FAILED status, I also want to know the results from each testStep. Again, how to script this?

    I tried the following, did not work:(
    for(result in runner.results)
    {
    log.info result.getTestCase().name
    if(result.getStatus().toString() == 'FAILED')
    {
    log.info "TestCase has failed"
    for(a in result.getTestCase.results())
    {
    log.info a
    }
    }
    }
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Finan,

    This should work:
    for( testCaseResult in runner.results )
    {
    testCaseName = testCaseResult.getTestCase().name
    log.info testCaseName
    if( testCaseResult.getStatus().toString() == 'FAILED' )
    {
    log.info "$testCaseName has failed"
    for( testStepResult in testCaseResult.getResults() )
    {
    testStepResult.messages.each() { msg -> log.info msg }
    }
    }
    }


    I've added it to the Scripting Tips & Tricks page.

    /Henrik
    eviware support
    • harish4b4's avatar
      harish4b4
      Senior Member

      When I use above code...It is printing results in random order.

      i.e let say i have test cases named with A,B and C in order..when I run above code multiple times it prints results in random order like C,A,B or B,A,C.

      In order to prepare Customized HTML reports i want to access results in order.Can some one give solution ASAP.

      Thanks in advance.

       

  • Finan's avatar
    Finan
    Frequent Contributor
    Hi,

    Thx for the script! It gave me enough clues to solve this part of my scripting puzzle