【问题标题】:Can't get a scenario's filename from scenario.file in Cucumber 2.3.2无法从 Cucumber 2.3.2 中的场景文件中获取场景的文件名
【发布时间】:2016-02-25 15:09:39
【问题描述】:

我在 Rails 应用程序 /features/support/hooks.rb 中有这段代码:

After do |scenario|
  if scenario.failed?
    filename = "#{FAILED_DIR_PATH}/failed--#{scenario.file.gsub("features/","").gsub("/","-")}--#{scenario.line}.html"
    Capybara.save_page filename
  end
end

如果文件/features/user_features/user_login.feature12 行的场景失败,则使用默认的水豚页面转储文件名

tmp/capybara/capybara-5654648798738734.html

转储将以更好的文件名保存:

tmp/capybara/failed--user_features-user_login.feature--12.html

所以如果有很多失败,我会立即知道哪个转储是正确的。

这在 Cucumber 1.3.2 中有效。

今天我更新了 gems 并得到了Cucumber 2.3.2 并得到了这个错误:

 undefined method `file' for #<Cucumber::RunningTestCase::Scenario:0x007f9598abb230>

如果我调试它,scenario 就只有这些方法:

Cucumber::RunningTestCase::Scenario#methods: 

accept_hook?  exception  failed?  outline?  passed?  skip_invoke!  source_tag_names  source_tags  status  title   with_result

我唯一能找到文件名的地方是scenario.exception.backtrace(深埋在Capybara文件下面)。

现在是否有可能获取场景文件路径和场景开始的行号?

【问题讨论】:

  • 感谢 Dave 对我的问题进行了令人难以置信的更正和改进。

标签: ruby cucumber hook scenarios


【解决方案1】:

在 Cucumber 2 中,filelinescenariolocation 的属性,而不是 scenario 本身的属性。将scenario.file 替换为scenario.location.file,将scenario.line 替换为scenario.location.line

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多