繁体   English   中英

groovy.lang.MissingPropertyException:没有此类属性:类文件:第5行的Script7错误

[英]groovy.lang.MissingPropertyException: No such property: file for class: Script7 error at line 5

我正在编写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')

测试套件属性

测试用例

请按照以下步骤操作:

  • 转到PostPaid Test Suite
  • 在要保存请求和响应的目录名称中添加一个自定义属性,例如DATA_STORE_PATH及其值
  • 转到测试用例PostPaid_Success_Payment
  • 禁用步骤2和步骤3,即SaveInquiryReqSaveInquiryResponse步骤。 或者,如果除了保存请求和响应以外没有其他工作,也可以删除altoger。
  • 单击step1 BillInq ,单击断言,选择Script Assertion ,有关更多详细信息,请参见此处, 如何添加脚本断言
  • 有以下脚本,然后单击确定
  • 现在运行步骤1,您应该能够看到保存在上述目录中的请求和响应
/**
 * 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM