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

时间:2016-10-30 11:20:44

标签: groovy soapui

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

Test Suite properties

Test case

1 个答案:

答案 0 :(得分:1)

请按照以下步骤操作:

  • 转到测试套件PostPaid
  • 将自定义属性DATA_STORE_PATH及其值添加到您要保存请求和响应的目录名称
  • 转到测试用例PostPaid_Success_Payment
  • 禁用第2步&第3步,即SaveInquiryReqSaveInquiryResponse步骤。或者除了保存请求之外,如果没有其他工作,你也可以删除altoger。分别回应。
  • 点击第1步BillInq,点击断言,选择Script Assertion,点击此处了解详情how to add script assertion
  • 有以下脚本并单击确定
  • 现在你运行step1,你应该能够看到保存在上述目录中的请求和响应
/**
 * 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)