1

我有使用十进制值的基本黄瓜场景大纲:

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 似乎将小数点前后的数字拆分为单独的 args 当 /^I 从引擎大小过滤器中选择 (\d+).(\d+) 升和 (\d+).(\d+) 升下拉字段时$/ 做 |arg1, arg2, arg3, arg4|

当我执行 .rb 文件时,出现以下错误:

在选择列表中找不到“1”(Watir::Exception::NoValueFoundException)

如何让红宝石将十进制值视为一个参数?可能是新手的错误,但那是我的水平。

谢谢!

4

1 回答 1

2

I assume you are using the suggested step definition by Cucumber? These are not always correct for the data you are using, so you sometimes need to tweak the step definition's regex.

You want:

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

If you need a regex tutorial, I have found this one to be pretty good - http://www.regular-expressions.info/tutorial.html.

Note that arg1 and arg2 will be strings. If you want them as decimals, you will need to convert them using to_f(). For example:

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

Update

It looks like you are trying to select the value from a dropdown using Watir. In that case, I am guessing you actually want arg1 to actually be "1.1 Litres" not "1.1". If so, you will want to include Litres in the brackets:

When /^I select (.+ Litres) and (.+ Litres) dropdown fields from the Engine size filter$/ do |arg1, arg2|
于 2012-07-17T20:41:43.697 回答