tinoboehme
13 years agoOccasional Contributor
set StepMessages for logging
Hello,
I'm creating an individual log file after each test case (using the Project Event "TestRunListener.afterRun").
One part of my script:
After a test run my logfile contain following information (simplified):
This is the appropriate TestCase Log:
I'm using many "Groovy Script" test steps and I have to log some infos from these steps.
If I want to fail a groovy test step I'm using testRunner.fail("message, why this step failed")
Here my Questions:
1. how to access the fail message ("message, why this step failed")? It is not listed within testResult.getMessages()
2. how to set a "pass-message"? similar to the Property Transfer messages ("Performed transfer [user]")
I still tried to add my individual logs & messages to the "script log", append to log file and clean up the script logs.
But with this solution it is difficult (but possible) to map these logs to each step. This solution work only if all testcases run in a secuence.
But if I run some testcases in parallel it is not possible to mapp the script log to each testRun
Does have anyone an idea so solve this issue?
Regards Tino
I'm creating an individual log file after each test case (using the Project Event "TestRunListener.afterRun").
One part of my script:
for( testResult in testRunner.getResults() ) {
def testStep = testResult.getTestStep()
def stepType = testStep.config.type
def stepName = testStep.getLabel()
def stepDesc = testStep.getDescription()
def stepStatus = testResult.getStatus().toString()
def stepDuration = testResult.getTimeTaken()
def stepMsg = testResult.getMessages()
def stepErr = testResult.getError()
logFile.append(seperator)
logFile.append("# TestStep: " + stepName + " (type: " + stepType + ")\r\n")
if (stepDesc != null && stepDesc.toString().length() > 0){
logFile.append("# Description: " + stepDesc.toString() + "\r\n")
}
// print TestStepResult (incl. error message)
logFile.append("# Result: " + stepStatus.toString() +" (duration " + stepDuration.toString() + "ms)\r\n")
if (stepMsg.size() > 0){
for (msg in stepMsg) logFile.append("# "+ msg + "\r\n")
}
if (stepErr != null){
logFile.append("# "+ stepErr + "\r\n")
}
}
After a test run my logfile contain following information (simplified):
####################################################################################################
# TestStep: Properties (2) (type: properties)
# Result: OK (duration 2ms)
####################################################################################################
# TestStep: Property Transfer (type: transfer)
# Result: OK (duration 8ms)
# Performed transfer [user]
# Performed transfer [password]
####################################################################################################
# TestStep: mySOAP-Request (type: request)
# Result: FAILED (duration 15ms)
# java.lang.ClassCastException: org.apache.http.message.BasicHttpRequest cannot be cast to org.apache.http.impl.client.RequestWrapper
####################################################################################################
This is the appropriate TestCase Log:
I'm using many "Groovy Script" test steps and I have to log some infos from these steps.
If I want to fail a groovy test step I'm using testRunner.fail("message, why this step failed")
Here my Questions:
1. how to access the fail message ("message, why this step failed")? It is not listed within testResult.getMessages()
2. how to set a "pass-message"? similar to the Property Transfer messages ("Performed transfer [user]")
I still tried to add my individual logs & messages to the "script log", append to log file and clean up the script logs.
But with this solution it is difficult (but possible) to map these logs to each step. This solution work only if all testcases run in a secuence.
But if I run some testcases in parallel it is not possible to mapp the script log to each testRun

Does have anyone an idea so solve this issue?
Regards Tino