2012-07-17 50 views
0

我有基本的黃瓜方案大綱,其中我使用十進制值處理連字符:Cucmber /紅寶石 - 方案概述 - 小數,爲多個參數

Given I have clicked the Search Button 
When I select <MinEngineSize> and <MaxEngineSize> dropdown fields from the Engine size filter 
And I click the Show results button 
Then the search results are displayed 

例子:

|MinEngineSize|MaxEngineSize| 
|1.1 Litres|1.6 Litres| 

出於某種原因ruby似乎將小數前後的數字拆分爲單獨的參數 當/^I選擇(\ d +)。(\ d +)公升和(\ d +)。(\ d +)公差大小過濾器的下拉字段$/do | arg1,arg2,arg3,arg4 |

當我執行.RB文件我得到follwing錯誤:

「1」不是在選擇列表中(的Watir ::例外:: NoValueFoundException)

如何獲得紅寶石湯治療的十進制值作爲一個arg?可能是一個新手的錯誤,但那是我在莫級的水平。

謝謝!

回答

1

我假設您使用Cucumber建議的步驟定義?這些對於你所使用的數據來說並不總是正確的,所以你有時需要調整步驟定義的正則表達式。

你想:

When /^I select (.+) Litres and (.+) Litres dropdown fields from the Engine size filter$/ do |arg1, arg2| 

如果你需要一個正則表達式的教程,我發現這一個是相當不錯的 - http://www.regular-expressions.info/tutorial.html

請注意,arg1和arg2將是字符串。如果你想將它們作爲小數點,你需要使用to_f()來轉換它們。例如:

When /^I select (.+) Litres and (.+) Litres dropdown fields from the Engine size filter$/ do |arg1, arg2| 
    numeric_arg1 = arg1.to_f 
    numeric_arg2 = arg2.to_f 

更新

它看起來像你想選擇使用的Watir下拉值。在這種情況下,我猜你實際上希望arg1實際上是「1.1升」而不是「1.1」。如果是這樣,你會想在括號中包括公升:

When /^I select (.+ Litres) and (.+ Litres) dropdown fields from the Engine size filter$/ do |arg1, arg2| 
+0

啊天才它的工作!感謝您的教程鏈接和您的幫助! – user1365374 2012-07-18 08:01:46