2016-10-30 31 views
0

我写Groovy脚本保存原始SOAP请求&反应,我得到这个错误:groovy.lang.MissingPropertyException:没有这样的属性:文件类:Script7误差在5号线

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

这里是脚本:

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

+0

有将其在管线5.您可以测试套件性能和测试用例的屏幕截图中使用的脚本创建任何'file'对象?您是否在'Billing'测试步骤的'Script Assertion'中使用它。你看起来似乎有几个星期和不同的问题有问题。 – Rao

+0

是的,我修复了报告自动生成现在我想记录每个肥皂测试步骤的原始请求和响应的步骤名称,我终于使用了上面的脚本,但是当我使用参考值时,我得到了提到的错误 –

+0

感谢您的编辑。剧本在哪里?或步骤号码?顺便说一下,不知道为什么有多个groovy脚本。每一件事都可以一步完成。任何方式,请澄清。 – Rao

回答

1

请按照下列步骤操作:

  • 去考套房PostPaid
  • 添加自定义属性说DATA_STORE_PATH并将其值改为目录名,你要保存的请求和响应
  • 去考案例
  • 禁用步骤2 &步骤3即SaveInquiryReqSaveInquiryResponse步骤。或者如果除了分别保存请求&响应之外没有其他工作完成,您也可以删除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) 
+0

它的工作原理,非常感谢,但请求添加了引用不是原始请求 –

+0

你很快尝试答案。更新了'rawRequest'的脚本。如果这有帮助,考虑如果回答并投票。 – Rao

+0

非常感谢它现在的作品 –

相关问题