Ask a Question

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

SOLVED
Sirisha2020
Contributor

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.

7 REPLIES 7
sonya_m
SmartBear Alumni (Retired)

@HimanshuTayal , @nmrao @msiadak  @PrathapR 

Any ideas on what might be the cause? Thank you!

 


Sonya Mihaljova
Community and Education Specialist

HimanshuTayal
Community Hero

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


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

Hi,

 

We are using GET request to get the details. 

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)

Sirisha2020
Contributor

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 .

 

Sirisha2020
Contributor

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
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! 


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: