cancel
Showing results for 
Search instead for 
Did you mean: 

i want to save REST Response on test case level to a notepad or to any other file using soap ui

SOLVED
Highlighted
Occasional Contributor

i want to save REST Response on test case level to a notepad or to any other file using soap ui

 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: i want to save REST Response on test case level to a notepad or to any other file using soap ui

@Sirisha2020 :

 

Hope below code will help you out in saving response to txt file, it will work in tear down script of test case:

 

import groovy.json.JsonOutput;

testCase.testStepList.each{
	type = it.config.type
	name = it.name
	response = it.getPropertyValue("Response")
	if(type == "restrequest"){
		def pretty = JsonOutput.prettyPrint(response);
		def responseFile="F://testing//"+name.toString()+"__response.txt";
		def rsfile = new File(responseFile);
		rsfile.write(pretty, "UTF-8");
	}
}

 


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



Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
Highlighted
Community Leader

Re: i want to save REST Response on test case level to a notepad or to any other file using soap ui

@Sirisha2020 :

 

Hope below code will help you out in saving response to txt file, it will work in tear down script of test case:

 

import groovy.json.JsonOutput;

testCase.testStepList.each{
	type = it.config.type
	name = it.name
	response = it.getPropertyValue("Response")
	if(type == "restrequest"){
		def pretty = JsonOutput.prettyPrint(response);
		def responseFile="F://testing//"+name.toString()+"__response.txt";
		def rsfile = new File(responseFile);
		rsfile.write(pretty, "UTF-8");
	}
}

 


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



Thanks and Regards,
Himanshu Tayal

View solution in original post

Community Manager

Re: i want to save REST Response on test case level to a notepad or to any other file using soap ui

Thank you Himanshu🙂

 

@Sirisha2020 Does this code help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: i want to save REST Response on test case level to a notepad or to any other file using soap ui

Hi Himanshu,

 

i am able to write the response to a document. But i am trying to update the request to a separate word document it is not saving the request along with the time stamp to the word document. Please find the code as below :

 

def rawRequest = JsonOutput.prettyPrint(request);
def file1 = new File("C://Users//appu//Desktop//proj//groovy1.doc");
file1.write (rawRequest,"UTF-8");

I tried various ways to get the request but no luck. Also i want to save request and response along with time stamp.

 

Thanks.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors