2016-09-28 102 views
1

我的用例是我想在多個SoapUI項目中對請求體進行批量更新。如何在SoapUI context.expand表達式中使用嵌套參數?

請求正文的示例。

{ 
"name": "${#TestSuite#NameProperty}" 
"id": "${#TestSuite#IdProperty}" 
} 

我想擴大屬性$ {##的TestSuite} NameProperty通過Groovy和獲取存儲在TestSuite的水平值,然後根據需要進行修改。

假設我在測試用例中有50個測試步驟,並且我想從Groovy腳本擴展每個請求。要擴展特定的測試步驟,我會傳遞測試步驟的名稱。例如:

expandedProperty = context.expand('${testStep1#Request}') 

但是,如果我想迭代所有50個測試步驟,我該怎麼做到這一點呢?我試圖在context.expand表達式中使用嵌套參數,但它不起作用。例如:

currentTestStepName = "TestStep1" 
expandedProperty = context.expand('${${currentTestStepName}#Request}') 

這隻返回我從測試步驟正上方(其中我正在從Groovy腳本),而不是「TestStep1」一步擴展要求。 (這是瘋狂的!)

此外,context.expand似乎只能通過從SoapUI工作區項目通過Groovy腳本執行。是否有其他方式或方法類似於context.expand,它可以在無頭執行期間擴展像「$ {#TestSuite#NameProperty}」這樣的屬性?例如:在SoapUI中導入的Groovy編譯的jar文件。

感謝您提前提供任何幫助!

+0

我想通過構建一個總和爲實際TestStep名稱的字符串,它的工作方式。但是,我希望可能有一個更簡單的方法來做到這一點。示例:** string =「\ $」+「{TestStep1#Request}」**然後展開字符串** context.expand(string)** – Dighate

+0

您的用例是什麼?只是想把測試的所有請求寫到一些地方? Groovy腳本是否在同一個測試用例中? – Rao

+0

在原始問題中更新了我的用例。 – Dighate

回答

2

您可以使用context.expand('${${currentTestStepName}#Request}')獲取它。

還有其他的方法,它不使用context.expand。

爲了得到任何給定的測試步驟的單個測試步驟請求:

這裏用戶通過步驟名到可變stepName

log.info context.testCase.testSteps[stepName].getPropertyValue('Request') 

如果你想獲得測試用例的所有請求,下面是使用下面的腳本的簡單方法。

/** 
* This script loops thru the tests steps of SOAP Request steps, 
* Adds the step name, and request to a map. 
* So, that one can query the map to get the request using step name any time later. 
*/ 
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep 
def requestsMap = [:] 
context.testCase.testStepList.each { step -> 
    log.info "Looking into soap request step: ${step.name}" 
    if (step instanceof WsdlTestRequestStep) { 
     log.info "Found a request step of required type " 
     requestsMap[step.name] = context.expand(step.getPropertyValue('Request')) 
    } 
} 
log.info requestsMap['TestStep1'] 

更新: 如果你有興趣的一步是一步REST,使用下面的條件,而不是在上面WsdlTestRequestStep

if (step instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) { //do the stuff } 
+0

我試圖使用getPropertyValue('Request'),但它返回實際的字符串,包括「$ {#TestSuite#NameProperty}」。但是,我想要「$ {#TestSuite#NameProperty}」中的實際值,這就是我嘗試使用context.expand的原因。 – Dighate

+0

爲什麼要替換值'$ {#TestSuite#NameProperty}',而不是更改屬性值。 – Rao

+0

我正在處理的批量更新實用程序涉及將JSON請求轉換爲具有不同結構的新的實例。另外,我無法更改屬性,因爲在更新屬性之前我有一些滿足條件需要檢查。 – Dighate

相關問題