Cucumber - 场景标题中的变量而不在正文中使用它

问题描述

在 Cucumber 中,我想在标题中使用变量而不在正文中使用它。 例如:

 Scenario Outline: Test case described at <excel_line>
    Given the following devices
      | name    | type     |
      | device  | <device> |
    When a <device> is active
    Then I get a message
    Examples:
    | device  | excel_line  |
    | Android | 1           |
    | IPhone  | 2           |

如您所见, 仅在标题中有所不同,不应在正文中使用。

这可能吗?

解决方法

我可以在一个项目中找到我满意的解决方法。 变量用在正文中,但至少看起来不是这样。

执行如下步骤(如果是 Ruby)

Given('Scenario title: {string}') do |scenario_title|
  puts "scenario_title : #{scenario_title}"
end

然后:

 Scenario Outline:
    * Scenario title: Test case described at <excel_line>
    Given the following devices
      | name    | type     |
      | device  | <device> |
    When a <device> is active
    Then I get a message
    Examples:
    | device  | excel_line  |
    | Android | 1           |
    | IPhone  | 2           |

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...