Forum Discussion

kgbheem's avatar
kgbheem
Occasional Contributor
7 years ago

how do i get the assertions list test data wise in a test

i have scenario where i used datasoure to  validate for multiple test data, here i want to get the assertions test datawise

like  testdata1

              1. assertion passed( need to print actual value i.e Firstname= kiran1)

              2. assertion passed( need to print actual value i.e lastname= kiran1)

testdata2

              1. assertion passed( need to print actual value i.e Firstname= kiran2)

              2. assertion passed( need to print actual value i.e lastname= kiran2)

testdata3

              1. assertion passed( need to print actual value i.e Firstname= kiran3)

              2. assertion passed( need to print actual value i.e lastname= kiran3)

 

currently im able to print the assertions with label and status 3 times( 3 test data)

here is my code 

 

def testStep = testRunner.testCase.getTestStepByName("Oip_find_Invalid_Data")
def list = testStep.getAssertionList()
for( assertion in list)
{
if(assertion.status == AssertionStatus.FAILED){

log.info "Verify ${assertion.label}","${assertion.status}"
}else if(assertion.status == AssertionStatus.VALID){
log.info "Verify ${assertion.label}","${assertion.status}"
}else if(assertion.status == AssertionStatus.UNKNOWN){
log.info "${assertion.label}", "${assertion.status}"
}
}

Please help me

 

  • While not exactly what you requested, the following code can be placed into a TestRunListener.afterRun event handler it shows you how to get hold of the assertion error message that Ready API displays:

     

    import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
    
    def logPrefix = testRunner.getTestCase().getName() + ': '
    
    // Loop through all of the test step results.
    testRunner.getResults().each(){ testStepResult ->
    
    	log.info(logPrefix + 'Test step ' + testStepResult.getTestStep().getName() + ' result status = ' + testStepResult.getStatus().toString())
    
         // Loop through all of the assertions.
         testStepResult.getTestStep().getAssertionList().each() { assertion ->
    
    		log.info(logPrefix + 'Assertion ' +  assertion.getName() +  ' returned status = ' + assertion.getStatus())
    
    		// Check to see if current assertion has failed?
    	     if(assertion.getStatus().toString().equals('FAILED')){
    
    			// Loop through all of the failed assertions error messages
    			assertion.getErrors().each() { assertionError ->
    	      		log.info(logPrefix + assertionError.getErrorLevel().toString() + ' message = ' + assertionError.getMessage())
    	      	}
    	     }
         }
    }

     

    Hopefully this will get you started.

  • Radford's avatar
    Radford
    Super Contributor

    While not exactly what you requested, the following code can be placed into a TestRunListener.afterRun event handler it shows you how to get hold of the assertion error message that Ready API displays:

     

    import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
    
    def logPrefix = testRunner.getTestCase().getName() + ': '
    
    // Loop through all of the test step results.
    testRunner.getResults().each(){ testStepResult ->
    
    	log.info(logPrefix + 'Test step ' + testStepResult.getTestStep().getName() + ' result status = ' + testStepResult.getStatus().toString())
    
         // Loop through all of the assertions.
         testStepResult.getTestStep().getAssertionList().each() { assertion ->
    
    		log.info(logPrefix + 'Assertion ' +  assertion.getName() +  ' returned status = ' + assertion.getStatus())
    
    		// Check to see if current assertion has failed?
    	     if(assertion.getStatus().toString().equals('FAILED')){
    
    			// Loop through all of the failed assertions error messages
    			assertion.getErrors().each() { assertionError ->
    	      		log.info(logPrefix + assertionError.getErrorLevel().toString() + ' message = ' + assertionError.getMessage())
    	      	}
    	     }
         }
    }

     

    Hopefully this will get you started.