【问题标题】:Cucmber/Ruby - Scenario Outline - Decimals, hyphens treated as multiple argumentsCucumber/Ruby - 场景大纲 - 小数,连字符被视为多个参数
【发布时间】:2012-07-17 16:18:54
【问题描述】:

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

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+) Liters 和 (\d+).(\d+) Liters 下拉字段时,请执行 |arg1, arg2, arg3, arg4|

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

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

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

谢谢!

【问题讨论】:

    标签: cucumber qa


    【解决方案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|
    

    【讨论】:

    • 啊天才成功了!!感谢您的教程链接和您的帮助!
    猜你喜欢
    • 2019-12-15
    • 2021-03-11
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多