Ask a Question

how to collect assertion message from Assertion Teststep

SOLVED
Said
Contributor

how to collect assertion message from Assertion Teststep

Hi,

 

For reporting I have a test step that calls below method in script library. This method collects all assertion messages from al test steps in the running test case.

 

public static String getTestCaseRunAssertionMessages( def testRunner, def context, def log ) {
	log.debug "*** Method getTestCaseRunAssertionMessages ***"
	def testStepList = testRunner.getTestCase().getTestStepList()
	String assertErrors = ""
	testStepList.each {
		if ( it.isDisabled() == false ) {
			if ( it.metaClass.hasProperty( it, 'assertionStatus' ) ) {
				log.debug "Collecting assertion messages in: " + it.getName();
				for( assertion in it.assertionList ) {
					for( e in assertion.errors ) {
						log.debug "Failed assertions found in: " + it.getName();
						if ( assertErrors.equals("") ) {
							assertErrors = it.name + ": " + e.message;
						} else {
							assertErrors = assertErrors + "\n" + it.name + ": " + e.message;
						}
					}
				}
			}
		}
	}
	return assertErrors
}

 

My issue: the statement for( e in assertion.errors ) { does not go into the loop when the teststep is an "Assertion" test step. This assertion step has failed assertion. Is there is work around for this?

1 ACCEPTED SOLUTION

Accepted Solutions
Said
Contributor

Re: how to collect assertion message from Assertion Teststep

With help from Smartbear support I found the solution. For assertion test step the code to collect assertion messages is slightly different: see below...

 

 

public static String getTestCaseRunAssertionMessages( def testRunner, def context, def log ) {
	log.debug "*** Method getTestCaseRunAssertionMessages ***"
	def testStepList = testRunner.getTestCase().getTestStepList()
	String assertErrors = ""
	if (context.requestAttempt >= 3 ) {
		assertErrors = "Stop processing after " + context.requestAttempt + " request attempts";
	}
	testStepList.each {
		if ( it.isDisabled() == false ) {
			log.debug it.getClass()
			// Collecting assertion messages differs from AssertionTestStep and wsdl/rest steps
			if ( it.getClass().toString().contains( "AssertionTestStep") ) {
				log.debug "*** AssertionTestStep ***"
				def list = it.getAssertionEntryList()
				for( assertion in list) {
					for (err in assertion.getAssertion().getErrors()) {
						log.debug "Failed assertions found in: " + it.getName();
						if ( assertErrors.equals("") ) {
							assertErrors = it.name + ": " + err.getMessage();
						} else {
							assertErrors = assertErrors + "\n" + it.name + ": " + err.getMessage();
						}
					}
				}
			} else if ( it.metaClass.hasProperty( it, 'assertionStatus' ) ) {
				log.debug "Collecting assertion messages in: " + it.getName();
				for( assertion in it.assertionList ) {
					for( e in assertion.errors ) {
						log.debug "Failed assertions found in: " + it.getName();
						if ( assertErrors.equals("") ) {
							assertErrors = it.name + ": " + e.message;
						} else {
							assertErrors = assertErrors + "\n" + it.name + ": " + e.message;
						}
					}
				}
			}
		}
	}
	return assertErrors

 

 

View solution in original post

3 REPLIES 3
nmrao
Community Hero

Re: how to collect assertion message from Assertion Teststep

Is there a stacktrace of the error?


Regards,
Rao.
Said
Contributor

Re: how to collect assertion message from Assertion Teststep

I checked ready-api-errors.log: no stacktrace.

Said
Contributor

Re: how to collect assertion message from Assertion Teststep

With help from Smartbear support I found the solution. For assertion test step the code to collect assertion messages is slightly different: see below...

 

 

public static String getTestCaseRunAssertionMessages( def testRunner, def context, def log ) {
	log.debug "*** Method getTestCaseRunAssertionMessages ***"
	def testStepList = testRunner.getTestCase().getTestStepList()
	String assertErrors = ""
	if (context.requestAttempt >= 3 ) {
		assertErrors = "Stop processing after " + context.requestAttempt + " request attempts";
	}
	testStepList.each {
		if ( it.isDisabled() == false ) {
			log.debug it.getClass()
			// Collecting assertion messages differs from AssertionTestStep and wsdl/rest steps
			if ( it.getClass().toString().contains( "AssertionTestStep") ) {
				log.debug "*** AssertionTestStep ***"
				def list = it.getAssertionEntryList()
				for( assertion in list) {
					for (err in assertion.getAssertion().getErrors()) {
						log.debug "Failed assertions found in: " + it.getName();
						if ( assertErrors.equals("") ) {
							assertErrors = it.name + ": " + err.getMessage();
						} else {
							assertErrors = assertErrors + "\n" + it.name + ": " + err.getMessage();
						}
					}
				}
			} else if ( it.metaClass.hasProperty( it, 'assertionStatus' ) ) {
				log.debug "Collecting assertion messages in: " + it.getName();
				for( assertion in it.assertionList ) {
					for( e in assertion.errors ) {
						log.debug "Failed assertions found in: " + it.getName();
						if ( assertErrors.equals("") ) {
							assertErrors = it.name + ": " + e.message;
						} else {
							assertErrors = assertErrors + "\n" + it.name + ": " + e.message;
						}
					}
				}
			}
		}
	}
	return assertErrors

 

 

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: