Capturing Request and Response XML in log file

本文介绍如何使用Groovy脚本在SoapUI中记录HTTP请求及响应到日志文件的方法。通过创建一个Script Test Step,并运行提供的Groovy脚本,可以将每次请求及其对应的响应保存为单独的文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自:https://community.smartbear.com/t5/SoapUI-NG/Capturing-Request-and-Response-XML-in-log-file/td-p/15991

Hello,

There is a dump file property which captures the raw response data, but not the request. I think the easiest way of capturing both the request and the response is by writing a groovy script to do so. Add a Script TestStep after the Request with the following script:


def timestamp = System.currentTimeMillis()
def directory = "c:\\dump"

def requestFile = new File(directory, "request_${timestamp}.txt")
requestFile.append( context.expand('${HTTP Test Request#Request}') )

def responseFile = new File(directory, "response_${timestamp}.txt")
responseFile.append( context.expand('${HTTP Test Request#Response}') )



This will save each request and response to a separate file.

Alternatively, if all you want to do is output them to the log, you can use:


log.info context.expand('${HTTP Test Request#Request}')
log.info context.expand('${HTTP Test Request#Response}')



In either case, replace HTTP Test Request with the name of your TestStep name.

Regards,
Dain
eviware.com

转载于:https://www.cnblogs.com/z1500592/p/6769409.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值