Forum Discussion

Prabaharan's avatar
Prabaharan
Contributor
5 years ago

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

  • JHunt's avatar
    JHunt
    Community Hero

    Try this:

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

     

    • JHunt's avatar
      JHunt
      Community Hero

      Or this:

      def request = context.testCase.testSteps['JDBCQuery'].jdbcRequest.requestContent
      • Prabaharan's avatar
        Prabaharan
        Contributor

        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.