Forum Discussion

Sirisha2020's avatar
Sirisha2020
Contributor
4 years ago
Solved

How to save the request and response in a folder along with time stamp

Hi

I am trying to save the request and response in a folder along with time stamp. I am able to save the response with timestamp. But request is saving with empty file. please find the below code :

 

import groovy.json.JsonOutput;

testCase.testStepList.each{
type = it.config.type
name = it.name
response = it.getPropertyValue("Response")
request = it.getPropertyValue("Request")

if(type == "restrequest"){

def pretty = JsonOutput.prettyPrint(response);
def req = JsonOutput.prettyPrint(request);
date = new Date()
dateFormat = new java.text.SimpleDateFormat('yyyyMMdd-HHmmss')
shortDate = dateFormat.format(date)
def responseFile= "C://Users//SS//Desktop//proj//"+name.toString()+shortDate+"_response.doc";
def requestFile= "C://Users//SS//Desktop//proj//"+name.toString()+shortDate+"_request.doc";
def rsfile = new File(responseFile);
def reqfile = new File(requestFile);
rsfile.write(pretty, "UTF-8");
reqfile.write(req,"UTF-8");
}
}

Request file has the user name and password in encrypted form with multiple columns.

 

Thanks.

  • sonya_m's avatar
    sonya_m
    4 years ago

    Hi Sirisha2020 !

     

    This query involves custom scripting, let's see if what I found would be of help!

     

    This script gets the request data and raw response with headers:

     

    def myRequestStep = testRunner.testCase.getTestStepByName('TestStepName')
    def GetrequestData = new String(myRequestStep.testRequest.messageExchange.rawRequestData)
    def GetresponseData = new String(myRequestStep.testRequest.messageExchange.rawResponseData)
    log.info  ("Request = " + GetrequestData)
    log.info  ("Response = " + GetresponseData)

     

    You can try to modify this script to see if that would fit your needs! 

7 Replies

  • Sirisha2020 : What is the type of request(GET/PUT/POST/Other).. it will be helpful if you could provide any screenshot of request.

    • Sirisha2020's avatar
      Sirisha2020
      Contributor

      Hi,

       

      We are using GET request to get the details. 

      • Sirisha2020's avatar
        Sirisha2020
        Contributor

        please find the raw request 

        GET https://XXXehwmanor001:9508/wma-rest/contracts/5EK6iiqaQRmE0GxUWeCDmQ%3D%3D HTTP/1.1
        Accept-Encoding: gzip,deflate
        X-XXX-Authn-Token: AQIC5wM2LY4Sfczk1CLpfbXvO7xPre1AxqUnfQuHHCfWXKs.*AAJTSQACMDEAAlNLABQtNDU5NTQ4NzkxNzU4NzEyMDA4NwACUzEAAA..*
        Host: xxxehwmanor001:9508
        Connection: Keep-Alive
        User-Agent: Apache-HttpClient/4.5.5 (Java/12.0.1)

  • please look at the below details. i am not getting the request details. It's bit urgent. I need solution for this. could you please look at my code.

     

    Thanks .

     

  • i checked soap ui log request log is displayed as below :

     

    Thu Oct 22 12:00:12 EDT 2020:DEBUG:Sending request: POST /vtg-rest/I1-bBdNbX6L1GmPaMXKKMQ%3D%3D/contracts/zatHdWzqwdIK-spMX7aZQQ%3D%3D/parties/bYLcK6zE-m2zLl3qB5oHLqmO5BOyiOqmGO2uZrZjHvA%3D/addresses HTTP/1.1
    Thu Oct 22 12:00:13 EDT 2020:DEBUG:Receiving response: HTTP/1.1 404 Not Found
    Thu Oct 22 12:00:13 EDT 2020:DEBUG:Connection shut down
    Thu Oct 22 12:00:13 EDT 2020:DEBUG:Attempt 1 to execute request
    Thu Oct 22 12:00:13 EDT 2020:DEBUG:Sending request: GET /vtg-rest/I1-bBdNbX6L1GmPaMXKKMQ%3D%3D/contracts/zatHdWzqwdIK-spMX7aZQQ%3D%3D/parties/bYLcK6zE-m2zLl3qB5oHLqmO5BOyiOqmGO2uZrZjHvA%3D/addresses HTTP/1.1
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Receiving response: HTTP/1.1 404 Not Found
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Connection shut down
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Attempt 1 to execute request
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Sending request: GET /vtg-rest/I1-bBdNbX6L1GmPaMXKKMQ%3D%3D/contracts/zatHdWzqwdIK-spMX7aZQQ%3D%3D/parties/bYLcK6zE-m2zLl3qB5oHLqmO5BOyiOqmGO2uZrZjHvA%3D/addresses/HOAQPBOwISOjyLlVVPIaiw%3D%3D HTTP/1.1
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Receiving response: HTTP/1.1 404 Not Found
    Thu Oct 22 12:00:14 EDT 2020:DEBUG:Connection shut down

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Hi Sirisha2020 !

       

      This query involves custom scripting, let's see if what I found would be of help!

       

      This script gets the request data and raw response with headers:

       

      def myRequestStep = testRunner.testCase.getTestStepByName('TestStepName')
      def GetrequestData = new String(myRequestStep.testRequest.messageExchange.rawRequestData)
      def GetresponseData = new String(myRequestStep.testRequest.messageExchange.rawResponseData)
      log.info  ("Request = " + GetrequestData)
      log.info  ("Response = " + GetresponseData)

       

      You can try to modify this script to see if that would fit your needs!