2012-07-24 77 views
1

有沒有在使用SoapUI的XPath測試中的斷言中使用通配符的方法?帶通配符的SoapUI XPath斷言

我看了一下了SoapUI的文檔,他們說你可以做這樣的事情

<path1> 
    <path2>*</path2> 
</path1> 

我查了「允許使用通配符」複選框。

我的問題是:我要堅持我的日期2012-08-22開始,但我不約分秒護理。我想我的表達應該是像2012-08-22 *,但它不起作用。

回答

2

你正在做的聲音是什麼樣的它應該工作。這裏是一個快速的例子,我使用http://www.geonames.org/export/web-services.html#timezone的休息服務來製作。我使用他們提供

演示

http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo 輸出

<geonames> 
    <timezone tzversion="tzdata2012c"> 
     <countryCode>AT</countryCode> 
     <countryName>Austria</countryName> 
     <lat>47.01</lat> 
     <lng>10.2</lng> 
     <timezoneId>Europe/Vienna</timezoneId> 
     <dstOffset>2.0</dstOffset> 
     <gmtOffset>1.0</gmtOffset> 
     <rawOffset>1.0</rawOffset> 
     <time>2012-07-25 04:39</time> 
     <sunrise>2012-07-25 05:50</sunrise> 
     <sunset>2012-07-25 21:00</sunset> 
    </timezone> 
</geonames> 

如果您對結果做一個XPath匹配和使用選擇從當前按鈕你

// GEONAMES /時區/時間

2012-07-25 04:39

如果更新這

// GEONAMES /時區/時間

2012-07-25 *

這將正常工作和更新與新的緯度其餘要求和液化天然氣的斷言依然會通過時,因爲它不檢查時間。如果這沒有幫助,請提供您的完整斷言,也許我可以幫助更多。

*注:爲SOAP請求,請務必聲明命名空間,然後使用正確的格式

//ns1:message 
+0

我有soapUI 3.6.1,這是行不通的。我得到以下斷言失敗的錯誤:'XPathContains comparaison failed,expect [2012-08-25 *],actual was [2012-08-25T00:00:00-04:00]' – Gab 2012-07-25 17:08:03

+0

奇怪的是,你認爲你發現一個問題3.6.1,當我在該版本中嘗試時遇到同樣的問題,只有這樣,我在該版本中的通配符工作是拉取整個請求,而不是特定字段,// ns1:message,從當前選擇,然後更新字段爲*。如果可以的話,我會升級。 – 2012-07-25 18:06:07

0

這將是不大不小的疼痛,但這裏是你可以做什麼:

1)找出一個XPath「基地」使用斷言標籤(聽起來像是你在這裏的話)。我用這個公共網站進行測試:http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl

我用'夏威夷'的角點方法作爲單參數。

我建立這個 '基地' 的xpath:

declare namespace ns1='http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl'; 
declare namespace SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'; 
declare namespace SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'; 

/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:CornerPointsResponse/listLatLonOut 

(it will write the declare statements for you if you click declare) 
(which you can test out in the assertions window) 

2)創建屬性步驟

3)創建屬性傳送步驟

4)創建Groovy腳本

5)添加屬性...我打電話給我的其它

6)添加TRANSF呃一步

* transfer from the CornerPoints - Request 1 --- Response 

* paste the Xpath stuff in the box under the 'transfer from' 

* Transfer to your property 

(You can test with the little play button) 

7)添加這樣的事情你的Groovy腳本:

def x = context.expand('${Properties#misc}') 
def parts = x.tokenize(',') 
for (def part in parts) 
{ 
    log.info(part) 
    if (part.startsWith("-153")) 
     log.info("good") 
} 

在常規步驟中,您可以做任何事情,你需要得到你的(部分)的數據。我添加的示例代碼從包裝在CDATA中的長行中獲取緯度/經度,然後檢查一些數據的起始部分。僅僅是一個例子。

記住,你可以使用Groovy和Java字符串方法:

http://groovy.codehaus.org/groovy-jdk/java/lang/String.html

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html

更多常規提示: http://www.soapui.org/Scripting-Properties/tips-a-tricks.html

+0

我其實是試圖避免常規 – Gab 2012-07-25 17:08:33

+0

不知道在這種情況下該怎麼做,但你可以減少我最初通過在實際的肥皂請求本身中進行常規斷言而提出了相當多的建議。那麼你不需要3個額外的步驟,只是在實際斷言中的一些常規。 – chrismead 2012-07-25 19:40:48