Unable to save the JDBC test step request through groovy
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this:
def request = context.testCase.testSteps['JDBCQuery'].query
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or this:
def request = context.testCase.testSteps['JDBCQuery'].jdbcRequest.requestContent
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@JHunt, Appreciate your help and timely response.
Let me know if there are any work around for this.
