cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to save the JDBC test step request through groovy

Highlighted
Occasional Contributor

Unable to save the JDBC test step request through groovy

Hi All,

 

I have created a JDBC test step and grrovy script test step to save the jdbc request and response automatically.

I was able to save the jdbc response as per expectation but not the request.

 

Below script for your reference

def myXmlRequest = "C:/Users/Prabaharans/Desktop/Notification/Database/" + TestCaseID + "_" + "SourceQuery_" + "Request" + ".xml"
def request = context.expand('${JDBCQuery#Request}')
def req = new File(myXmlRequest)
req.write(request, "UTF-8")

def myXmlResponse = "C:/Users/Prabaharans/Desktop/Notification/Database/" + TestCaseID + "_" + "SourceQuery_" + "Response" + ".xml"
def response = context.expand('${JDBCQuery#ResponseAsXml}')
def res = new File(myXmlResponse)
res.write(response, "UTF-8")

An empty file for request is getting created in the mentioned folder.

Appreciate if anyone can help me in resolving this

5 REPLIES 5
Community Hero

Re: Unable to save the JDBC test step request through groovy

Try this:

def request = context.testCase.testSteps['JDBCQuery'].query

 

Community Hero

Re: Unable to save the JDBC test step request through groovy

Or this:

def request = context.testCase.testSteps['JDBCQuery'].jdbcRequest.requestContent
Occasional Contributor

Re: Unable to save the JDBC test step request through groovy

Hi JHunt,

 

Thanks for your quick reply. Both your script works fine for saving the JDBC request to a file.

 

But I have implemented this project as a data driven for which few the values are fetched from an external file. The dynamic values are stored as a jdbc parameters.

 

Your scipt works fine for saving the jdbc request but saving the query without dynamic values.

Kindly refer the attachments.

 

Community Hero

Re: Unable to save the JDBC test step request through groovy

I checked the source code, and there is no available method you can call to get the query including the values. The values are added to a PreparedStatement in the middle of a protected method.

 

PreparedStatement is used to protect your database. Since they are designed to get around the limitations, and especially the risks, of using only Strings to send data to your database, it's not possible to convert them to String form.

Occasional Contributor

Re: Unable to save the JDBC test step request through groovy

@JHunt, Appreciate your help and timely response. 

Let me know if there are any work around for this.