2016-10-30 43 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

非常感謝它現在的作品 –

相關問題