Forum Discussion

tinoboehme's avatar
tinoboehme
Occasional Contributor
13 years ago

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:

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
  • tinoboehme's avatar
    tinoboehme
    Occasional Contributor
    Hello,

    could it be a possible solution to create an own Logging Class called myLog (in soapUI-Pro-4.5.1\bin\scripts\soapui\utils)
    and create an new Object with in the Project Event TestSuiteRunListener.beforeRun

    myLogHandler = new soapui.utils.myLog( context )
    myLogHandler.info("Test Case " + testCase + " starting")

    But how to access this Object "myLogHandler" at within a groovy script. Is it possible to save with in the testRunner object an reference to the myLog Object?

    myLogHandler = ????? // reference to myLog Object for this testRun
    myLogHandler.info("Test Step" + testStep + " starting")

    Regards Tino
  • Hi!

    1. Try
    runner.getReason() 
    to get the message passed to fail(...).

    2. Not sure what's the exact definition of a "pass message", but if you just want to add a message to the TestCase log, try adding
    testStepResult.addMessage "My custom message"
    to a TestRunListerner.afterStep event handler.

    Finally, if you want to save an object (such as your logger) you could use the TestSuite context like this:

    In TestRunListerner.beforeStep
    context.put("myInteger", new Integer(42))


    and access it from the Groovy TestStep like this:
    log.info context.getProperty( "#TestSuiteRunner#" ).runContext.get("myInteger")


    ---
    Regards
    Erik, SmartBear Sweden