ruby - 获取命令行 cucumber 标签

标签 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 的东西。

最后,我正在寻找一种方法来确保所有场景都针对各自的所有标签运行。

最佳答案

你可以使用AfterConfiguration hook

AfterConfiguration do |config|
  puts config.tag_expressions
end

关于ruby - 获取命令行 cucumber 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34050282/

相关文章:

ruby - 使用 S/MIME 在 Ruby 中对电子邮件进行数字签名

ruby-on-rails - rails : Converting currency from form to big decimal

css - 选择正文 :before with RSpec/XPath/CSS

ruby-on-rails - Webrat 说它找不到一些文本,但文本实际上在那里

ruby-on-rails - rails ruby​​ 遍历目录中的部分

ruby - redmine 安装失败,ruby 3.0.4,mysql2 (0.5.4) "undefined method ' split '""rb_enc_interned_str not found"

cucumber - Watir-webdriver 不断打开多个浏览器

ruby-on-rails - Rails - 我怎样才能只运行 cucumber 测试?

gradle - 我需要通过gradle调用Cucumber Runner,然后依次执行所有测试执行和报告

mysql - 对不属于表的元素进行排序