how to collect assertion message from Assertion Teststep
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2021
12:05 AM
10-29-2021
12:05 AM
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?
Solved! Go to Solution.
Labels:
- Labels:
-
Assertions
-
Function Tests
-
Reporting
-
Scripting
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2021
10:00 PM
10-31-2021
10:00 PM
Is there a stacktrace of the error?
Regards,
Rao.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2021
03:41 AM
11-01-2021
03:41 AM
I checked ready-api-errors.log: no stacktrace.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2021
02:41 AM
11-30-2021
02:41 AM
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
