Forum Discussion

gouseferoz's avatar
gouseferoz
New Contributor
8 years ago

logs are not getting generated correctly when use teardown script

I am using teardown script to log the status of each step of my project.

 

My Project outline:

Step 1: Datasource

Step 2 : HTTP step with Message content assertion

Step 3 : Datasource loop

 

My datasource has 3 lines of data so the loop will execute for three times. For the first two times the Step2 passes and for the third time the Step2 fails which is intended. 

But the log file i generated using the Teardown script is showing the Step2 as pass for the first two cases but the Message content assertion is showing errors which is the error that got for the third loop.

 

Teardown script:

 

log.info "Lets get Test run results"
def step_a = "";

step_a = "Test Case [" +testRunner.testCase.name+ "]\n"
for( r in testRunner.results )
{
       if ( r.testStep instanceof com.eviware.soapui.model.testsuite.Assertable)
      {
            step_a = step_a + " TestStep [ " + r.testStep.name + " ] finished with status " + r.status + "\n" ;
            if(!r.status.contains("OK"))
            {
                  for( assertion in r.testStep.assertionList )
                  {
                        step_a = step_a + "Assertion [" + assertion.label + "] has status [" + assertion.status + "]" + "\n";
                        for( e in assertion.errors )
                             step_a = step_a + "- Error [" + e.message + "]" + "\n";
                  }
             }  
        }
        else // Non-Assertable steps
       {
               step_a = step_a + " TestStep [ " + r.testStep.name + " ] finished with status " + r.status + "\n" ;
               // log.info step_a
        }
}
def groupID = context.expand( '${#Project#GroupID}' )
log.info groupID
def groupID1 = context.expand( '${#Global#GroupID}' )
log.info groupID1

File file = new File("C://SoapUI//Results//TestRunnerStatus.txt")
if( file.exists() ) {
file.append step_a
}
else{
file.write step_a
}

 

The Log file is something like this:

  1. Step 1 passed with status OK
  2. Step 2 passed with status OK
  3. Assertion Failed with message
  4. Step 3 passed with status OK
  5. Step 1 passed with status OK
  6. Step 2 passed with status FAILED
  7. Assertion Failed with message
  8. Step 3 passed with status OK
  9. Step 1 passed with status OK
  10. Step 2 passed with status FAILED
  11. Assertion Failed with message
  12. Step 3 passed with status OK

 

Please help me whats going wrong

  • I Got the resolution for my query. The below TearDown script will do the work:

     

    def step_a = "";
    for (testStepResult in testRunner.getResults() ) {
    def testStep = testStepResult.getTestStep()
    step_a = step_a + "TestStep [ " + testStep.name + " ] finished with status " + testStepResult.getStatus().toString() + "\n"
    //log.info testStep.testRequest.response.responseHeaders
    if (testStep instanceof com.eviware.soapui.model.testsuite.Assertable)
    {
    for( assertion in testStep.assertionList )
    {
    def messages = ""
    def isAssertionLogged = false
    for( message in testStepResult.getMessages() )
    {
    if(message.contains(assertion.name))
    {

    messages = messages + testStep.name + "- Error [" + message + "]" + "\n";;
    isAssertionLogged = true
    break
    }
    }

    if(isAssertionLogged) //if there is no error message for the assertion, the assertion is either passed (VALID) or was not ran (UNKNOWN)
    {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [FAILED]" + "\n";
    step_a = step_a + messages;
    }
    else {
    if(assertion.isDisabled()) {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [UNKNOWN]" + "\n"
    }
    else {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [OK]" + "\n"
    }
    }
    }
    }
    }//end for


    log.info "Let’s get Test run results"
    File file = new File("C:/Results/TestRunnerStatus20.txt")

    file.write step_a

  • lakshmiarun's avatar
    lakshmiarun
    SmartBear Alumni (Retired)

    Hi,

     

    Thank you for posting in our forum.

     

    I could see that you are working with one of our engineers through a case. Please continue to work him until the issue is resolved.

     

    Best,
    Lakshmi

  • gouseferoz's avatar
    gouseferoz
    New Contributor

    I Got the resolution for my query. The below TearDown script will do the work:

     

    def step_a = "";
    for (testStepResult in testRunner.getResults() ) {
    def testStep = testStepResult.getTestStep()
    step_a = step_a + "TestStep [ " + testStep.name + " ] finished with status " + testStepResult.getStatus().toString() + "\n"
    //log.info testStep.testRequest.response.responseHeaders
    if (testStep instanceof com.eviware.soapui.model.testsuite.Assertable)
    {
    for( assertion in testStep.assertionList )
    {
    def messages = ""
    def isAssertionLogged = false
    for( message in testStepResult.getMessages() )
    {
    if(message.contains(assertion.name))
    {

    messages = messages + testStep.name + "- Error [" + message + "]" + "\n";;
    isAssertionLogged = true
    break
    }
    }

    if(isAssertionLogged) //if there is no error message for the assertion, the assertion is either passed (VALID) or was not ran (UNKNOWN)
    {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [FAILED]" + "\n";
    step_a = step_a + messages;
    }
    else {
    if(assertion.isDisabled()) {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [UNKNOWN]" + "\n"
    }
    else {
    step_a = step_a + "Assertion [" + assertion.label + "] has status [OK]" + "\n"
    }
    }
    }
    }
    }//end for


    log.info "Let’s get Test run results"
    File file = new File("C:/Results/TestRunnerStatus20.txt")

    file.write step_a