我正在编写groovy脚本以保存原始肥皂请求&响应,我得到这个错误:
groovy.lang.MissingPropertyException:没有这样的属性:类的文件:第5行的Script7错误
这是脚本:
def myOutFile = context.expand( '${#TestSuite#fileName}' )+"_PostPaid-Success_Payment_BillInqReq.xml"
def response = context.expand( '${BillInq#Request}' )
def f = new File(myOutFile)
f.write(response, "UTF-8")
file.write(context.rawRequest,'utf-8')
答案 0 :(得分:1)
请按照以下步骤操作:
PostPaid
DATA_STORE_PATH
及其值添加到您要保存请求和响应的目录名称PostPaid_Success_Payment
SaveInquiryReq
和SaveInquiryResponse
步骤。或者除了保存请求之外,如果没有其他工作,你也可以删除altoger。分别回应。BillInq
,点击断言,选择Script Assertion
,点击此处了解详情how to add script assertion /**
* This script logs both request and response
*/
assert context.response, "Response is empty or null"
assert context.request, "Request is empty or null"
//Save the contents to a file
def saveToFile(file, content) {
if (!file.parentFile.exists()) {
file.parentFile.mkdirs()
log.info "Directory did not exist, created"
}
file.write(content)
assert file.exists(), "${file.name} not created"
}
def dirToStore = context.expand('${#TestSuite#DATA_STORE_PATH}')
def currentStepName = context.currentStep.name
def requestFileName = "${dirToStore}/${currentStepName}_request.xml"
def responseFileName = "${dirToStore}/${currentStepName}_response.xml"
//Save request & response to directory
saveToFile(new File(requestFileName), context.rawRequest)
saveToFile(new File(responseFileName), context.response)