[英]groovy.lang.MissingPropertyException: No such property: file for class: Script7 error at line 5
I am writing groovy script to save raw soap request & response and i get this error: 我正在编写groovy脚本以保存原始肥皂请求和响应,但出现此错误:
groovy.lang.MissingPropertyException: No such property: file for class: Script7 error at line 5 groovy.lang.MissingPropertyException:没有此类属性:类文件:第5行的Script7错误
Here is the Script: 这是脚本:
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')
Please follow the steps below: 请按照以下步骤操作:
PostPaid
转到PostPaid
Test Suite DATA_STORE_PATH
and its value to a directory name where you like to save the requests and responses 在要保存请求和响应的目录名称中添加一个自定义属性,例如DATA_STORE_PATH
及其值 PostPaid_Success_Payment
转到测试用例PostPaid_Success_Payment
SaveInquiryReq
and SaveInquiryResponse
steps. 禁用步骤2和步骤3,即SaveInquiryReq
和SaveInquiryResponse
步骤。 or you may remove altoger as well if no other work is done apart from save the request & response respectively. 或者,如果除了保存请求和响应以外没有其他工作,也可以删除altoger。 BillInq
, click on assertions, Choose Script Assertion
, see here for more details how to add script assertion 单击step1 BillInq
,单击断言,选择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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.