2012-07-17 18 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