Forum Discussion

bucuali's avatar
bucuali
Occasional Contributor
3 years ago

How to loop through results of individual test cases and recover testCase details

Hello everyone,

 

This will be my first post in the comunity and I've got to warn you, it's gonna be very oldscool

So here it goes. I recently "inherited an old SoapUI project which I am currently running in ReadyAPI and which need to modify.

 

I have a report generating script which is called from the teardown script of the other test cases via the following code:

 

testRunner.testCase.testSuite.project.testSuites["Library"].testCases["Reporting_Utility"].
testSteps["GenerateCSVReport"].run(testRunner, context);

 

On the other side, the report generate script is iterating through the test step results like so:

for(testCaseResult in runner.results())
{

def testSuite = testRunner.testCase.testSuite.name;
def testCase = testCaseResult.testCase.name //testRunner.testCase.name;
def testStep = stepResult.getTestStep();
def testStepName = testStep.name

reportFile.append('"' + testSuite + '",');
reportFile.append('"' + testCase + '",');

reportFile.append('"' + testStepName + '",');

reportFile.append('"' + status + '",' + "\n");

}

 

How can I loop through the results at test case level instead of the test step level?

I only need the overall fail/pass of each testcase.name + testsuite + status

Any help would be greatly appreciated

    • bucuali's avatar
      bucuali
      Occasional Contributor

      Hello MConneely ,

       

      Thanks for replying to the question. I am aware of the functionality but unfortunately it's not an option for my use case. My full requirement is the following: This project runs in Jenkins, and it has to return a .csv report which is sent from the pipeline to another app, at the same time a .pdf version of this report is sent by mail along with the Allure report (both mandatory). Now, the script runs fine, but the .csv and .pdf versions are very long as it shows all the test steps (around 400) and I have to reduce it's size by showing only test case results. Also, the app processing the .csv report has already been modified to expect test case results and process them accordingly, so no turning back at this point..

       

      Any ideas/resources on how to do this?

       

      Thank you in advance for the help 🙂 

      • MConneely's avatar
        MConneely
        Staff

        Hi bucuali,

         

        ive provided some options here, hopefully they will assist.
         

        In the Teardown Script tab of each Test Suite, you could have a version of the following
        for ( testCaseResult in runner.results )
        {
        // Get each test cases name from the suite
        testCaseName = testCaseResult.getTestCase().name

        // Get each test cases result

        testCaseStatus = testCaseResult.getStatus()

        //log the information
        log.info testCaseName + " :  " + testCaseStatus
        }

         

        If you wanted to move up a level and look at the results at a TestSuite level, you could put something at the Functional Test TearDown Script level
        for ( testSuiteResult in runner.results )
        {
        log.info(testSuiteResult.getTestSuite().getLabel() + " : " + testSuiteResult.getStatus())
        }

        Some samples on our documentation should assist you
        https://support.smartbear.com/readyapi/docs/testing/scripts/samples/index.html
        https://support.smartbear.com/readyapi/docs/testing/scripts/samples/log.html 


         

         


  • bucuali wrote:

    Hello everyone,

     

    This will be my first post in the comunity and I've got to warn you, it's gonna be very oldscool

    So here it goes. I recently "inherited an old SoapUI project which I am currently running in ReadyAPI and which need to modify.

     

    I have a report generating script which is called from the teardown script of the other test cases via the following code:

     

    testRunner.testCase.testSuite.project.testSuites["Library"].testCases["Reporting_Utility"].
    testSteps["GenerateCSVReport"].run(testRunner, context);

     

    On the other side, the report generate script is iterating through the test step results like so:

    for(testCaseResult in runner.results())
    {

    def testSuite = testRunner.testCase.testSuite.name;
    def testCase = testCaseResult.testCase.name //testRunner.testCase.name;
    def testStep = stepResult.getTestStep();
    def testStepName = testStep.name

    reportFile.append('"' + testSuite + '",');
    reportFile.append('"' + testCase + '",');

    reportFile.append('"' + testStepName + '",');

    reportFile.append('"' + status + '",' + "\n");

    }

     

    How can I loop through the results at test case level instead of the test step level?

    I only need the overall fail/pass of each testcase.name + testsuite + status

    Any help would be greatly appreciated


    If so, is the issue now around the reportFile object not getting populated? Is it the reportFile object read-in CSV file?

     

    • bucuali's avatar
      bucuali
      Occasional Contributor

      Hi Randall7205 

       

      Yes, that's the object. I's populated with individual test step data instead of overall test case (fail/pass) data.