Ask a Question

No test result saved in JDBC test cases when save test result in a file

deanding
New Contributor

No test result saved in JDBC test cases when save test result in a file

Hi, I'm trying to save test results of JDBC cases, but found that in the txt file, response data is not saved, please see the img

deanding_0-1700118543358.png

how can I write more data into test result txt file?

2 REPLIES 2
TNeuschwanger
Champion Level 2

Hello @deanding 

 

You will have to do some coding I think...

 

I assume (your question leads to a lot of assumptions) what you are showing is txt file from testrunner.bat execution...  What your img shows is the result of a test step not a test case... 

 

Those txt files are produced from every test step executed.  You will need to add a 'TestRunListener.afterStep' event listener for the project (right click on your project name | choose 'Events' from the available menu items).  I have some sandbox code below for that event (I found a little bit of the code searching this Smartbear site).  You can hack it up as needed. I have added a couple lines for a 'jdbc' step type at the end of this sample, but I have not tested it.  It may lead you to an ultimate solution by researching events further however.  🙂

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
import static com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.*
import static com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport.HTTP_METHOD
//
////Closure to get ExtendedHttpMethod object
//def eHM = { context.getProperty(HTTP_METHOD) }
//
////Initialize report
//def message = new StringBuilder()
//
////Add the test properties to report similar to failure case as this helps to understand easily if something is missing or incorrect
//def addPropertiesToReport = {
//            message.with {
//                append('\n----------------- Properties -----------------\n')
//                append("Endpoint: ${context.endpoint}\n")
//                switch (context.currentStep) {
//            case WsdlTestRequestStep:
//                append("Encoding: ${context.currentStep.testRequest.encoding}\n")
//                append("  ---  TESTING WsdlTestRequestStep \n")
//                break          
//            default:
//                           append("HTTP Version: ${eHM().protocolVersion}\n")
//                           append("Method: ${eHM().method}\n")
//                           append("StatusCode: ${testStepResult.getProperty('StatusCode')}\n")
//                           append("URL: ${eHM().URL}\n")
//                append("  ---  TESTING Default \n")                   
//                break
//       }
//    }    
//}
//
//def addPayLoadToReport = { subHead, content, additionalData = null ->
//            message.with {
//                            append("\n-------------- $subHead --------------\n")
//                            if(additionalData) {
//                                            append(eHM().requestLine).append('\n')
//                                            additionalData.each { append(it.name + ' :  ' + it.value + '\n')}
//                            }
//                            if (content) { append('\n').append(content).append('\n') }
//            }
//}
//
////Actual business logic
//if (([WsdlTestRequestStep, RestTestRequestStep, HttpTestRequestStep].any{context.currentStep in it}) && (testStepResult.status in [UNKNOWN, OK, PASS])) {
//            addPropertiesToReport()
//            addPayLoadToReport('Request', eHM().entity?.content?.text, eHM().allHeaders)
//            addPayLoadToReport('Response', context.rawResponse)              
//    testStepResult.addMessage(message.toString())
//}
 
// Get the test step's results, PASS or FAIL
def testStatus = testStepResult.getStatus();
 
// Get a reference to the test step
def testStep = testStepResult.getTestStep();
 
// Get the test type
def tsType = testStep.config.type.toString()
//  httprequest
//  groovy
//  properties
//  jdbc
 
//// Skip steps that are not soap or rest
//if (tsType.equals("soaprequest") || tsType.equals("restrequest"))
//{
//            // Skip tests that are not PASS
//            if (testStatus.toString().equals("PASS"))
//            {
//                            // Build full URL
//                            def endPoint = testStep.getHttpRequest().getEndpoint();
//                            def URI = testStepResult.getTestStep().getHttpRequest().getPath()
//                            def path = "$endPoint/$URI";
//
//                            def response = testStep.getPropertyValue("RawResponse");
//
//                            // Add the URL and raw response to the test step result messages, which flows to the test report.
//                            testStepResult.addMessage("Request URL: $path");        
//                            testStepResult.addMessage("Raw Response: $response");
//            }
//}
 
if (tsType.equals("httprequest")) {
   def environmentName = testRunner.testCase.project.getActiveEnvironment().name;
   testStepResult.addMessage(" ");
   testStepResult.addMessage("EnvironmentName = $environmentName" );
};
 
if (tsType.equals("properties")) {
   testStepResult.addMessage(" ");
   testStepResult.addMessage("First 25 char of Name...     First 100 char of Value...");
   testStepResult.addMessage("_________________________    ___________________________________________________________________________________________________");  
   //testStepResult.addMessage("Name -------------------    Value -------------------------------------------");
   for( prop in testStep.propertyNames  )
   {
      //log.info( prop + "=" + testStep.properties[prop].value );
//     webHostUnderTestBrowserFlavor = webHostUnderTestBrowserFlavor ?: 'chrome';  // if environment variable is not set, default to chrome...     
      name = prop ?: '';
      val = testStep.properties[prop].value ?: '';
      testStepResult.addMessage("${name.take(25).padRight(25,' ')}    ${val.take(100)}" );
   };
};
//testStepResult.addMessage("  ---   TESTING");
//testStepResult.addMessage(" --  ${testStep.name}");
//testStepResult.addMessage(" --  $tsType");

if (tsType.equals("jdbc")) {
   environmentName = testRunner.testCase.project.getActiveEnvironment().name;
   testStepResult.addMessage(" ");
   testStepResult.addMessage("EnvironmentName = $environmentName" );
   testStepResult.addMessage("****  More of your jdbc output needs are coded here  ****" );
//.
//  ****  More of your jdbc output needs are coded here  ****
//.

};

 

Give it a try and see what happens.

 

Regards,

Todd

Hey @TNeuschwanger,

Thanks for that. I had the same problem about 5 years ago where i had an event handler script extracting the request/response stuff for my test evidence, but i never sorted it for my JDBC steps, so nice one for this! Definitely worth some kudos! 😉

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: