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   M...
  • gouseferoz's avatar
    8 years ago

    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