Forum Discussion

SoapUser2012's avatar
SoapUser2012
Occasional Contributor
13 years ago

Get the Runstatus of all test cases in a testsuite in groovy

Hi ,

Though there exists already a similar thread ,I'm not able to get the right answer for my question . So, posting this as a new question .

Is it possible to get the run status "Finished/Failed" of each test case which are run as part of running test suite ?

I have a test suite comprising of 20 test cases .Need to run them in soap ui by clicking the "run" on testsuite in SoaupUI .
In the same suite i need to include a groovy script step at the end ,which runs after all the the test cases are done and would be able to read the results /test cases status of each test case and log the results to the external log file which we maintain .

Is it possible ?

thanks
  • Hi!

    sure - try

    for( r in runner.results )
    log.info r.status

    to print the result status of each TestCaseResult

    regards,

    /Ole
    SmartBear Software
  • SoapUser2012's avatar
    SoapUser2012
    Occasional Contributor
    Hi ,

    I'm not able to do that as I'm getting the exception .Do i need to take the context of test suite or how does it recognise "runner.results" when done in Groovy?

    and i also tried this in teardown script ,but not see results(logged info ) captured and shown in TestSuite log or anywhere.

    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 }
    }
    }
    }

    Teardown script code should automatically get executed after all the test cases are run .Where do i see the results of this tear down ?

    thanks
  • Hi!

    the log.info output is shown in the script log at the bottom of the main soapUI window.

    What exception did you get for the first script?

    regards,

    /Ole
    SmartBear Software
  • SoapUser2012's avatar
    SoapUser2012
    Occasional Contributor
    Hi ,

    Thank you ,i could see the script log . If i include the above code in 'Teardown script" i see the log in script log .

    However ,i'm not able to ale to get the test case results if i include this code in groovy script step .

    For ex,i have a groovy test script step in last test case. when i run the test suite,doesn't it executed and log the results of all the executed test cases?

    thanks
  • Hi,

    in a groovy-script teststep you can access the results of the previous testcases with

    def testSuiteRunner = context["#TestSuiteRunner#"]
    if( testSuiteRunner != null )
    {
    for( r in testSuiteRunner.results )
    log.info r.status
    }

    Obviously this won't contain the current TestCase as it hasn't finished yet

    regards!

    /Ole
    SmartBear Software