获取命令行黄瓜标记

时间:2015-12-02 18:27:31

标签: ruby cucumber

我有一个针对3个不同标签的功能。有些场景针对所有三个标签运行,有两个,一些仅针对一个。

@build_1 @build_2
Scenario: Test Case 1
Given I am on the home page
And I click the X button
Then I must see the text "function not available"

@build_1
Scenario: Test Case 2
Given I am on the home page
And I click the Y button
Then I must see the text "You pushed the Y button"

@build_2 @build_3
Scenario: Test Case 3
Given I am on the home page
And I click the Y button
Then I must see the text "function not available"

@build_3
Scenario: Test Case 4
Given I am on the home page
And I click the X button
Then I must see the text "Hey, this is neat!"

@build_1 @build_2 @build_3
Scenario: Test Case 5
Given I am on the home page
And I click the Z button
Then I must see the text "You pushed the Z button"

我使用三个不同的命令运行场景:

cucucmber features/my_test.feature --tags @build_1
cucucmber features/my_test.feature --tags @build_2
cucucmber features/my_test.feature --tags @build_3

我已经大大简化了我的代码,考虑到在构建之间切换所需的时间,我必须以这种方式运行测试。

有没有办法告诉哪个标签调用了当前的运行?使用

scenario.source_tag_names

给出了给定场景的所有标签,我正在寻找在命令行上指定的一个标签。如果我跑

cucucmber features/my_test.feature --tags @build_2

对于方案1,我得到了

scenario.source_tag_names = ["@build_1", "@build2", "@build_3"]

我想要的东西只是给@ build_2。

最后我要找的是确保所有场景都针对所有各自标签运行的方法。

1 个答案:

答案 0 :(得分:1)

您可以使用AfterConfiguration hook

AfterConfiguration do |config|
  puts config.tag_expressions
end
相关问题