我正在尝试清理我们正常工作的功能套件,我想知道是否有办法让黄瓜重复一个场景,看看是否有通过才能进入功能中的下一个场景? Phantom是我的无头webkit浏览器poltergeist是我的驱动程序。
基本上我们的构建一直处于失败状态,因为所有测试都会使框不堪重负,并且在一个场景中,页面将没有足够的时间来呈现我们正在尝试测试的任何内容。因此,这会产生误报。我知道没办法预测哪个测试会挂起构建。
在每个场景之后发生一个钩子(一个想法)会更好。如果场景通过,那么很好地打印该场景的结果并继续前进。但是,如果方案失败,那么尝试再次运行它只是为了确保它不是构建变得晕眩。然后,只有那时你打印那个场景的结果,然后继续下一个测试。
有没有人知道如何实现它?
我在想像
After do |scenario|
if scenario.failed?
result = scenario.run_again # I just made this function up I know for a fact this doesn't actually exist (see http://cukes.info/api/cucumber/ruby/yardoc/Cucumber/Ast/Scenario.html)
if !result
Cucumber.wants_to_quit = true
end
end
end
我看到的最初解决方案是:How to rerun the failed scenarios using Cucumber?
这没关系,但我需要确保
cucumber @rerun.txt
如果测试通过,实际上已经更正了报告。像
cucumber @rerun.txt --format junit --out foo.xml
foo.xml是junit报告,最初表示功能1,2和& 5人过去了,而3人和4人失败了,但现在会说1,2,3,4&尽管rerun.txt只表示重新运行3和4,但是5正在通过。
答案 0 :(得分:3)
我广泛使用rerun,是的,它确实将正确的功能输出到rerun.txt文件中。我有一个cucumber.yml文件,定义了一堆“配置文件”。请注意重新运行配置文件:
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
%>
<% standart_opts = "--format html --out report.html --format rerun --out rerun.txt --no-source --format pretty --require features --tags ~@wip" %>
default: <%= standart_opts %> --no-source --format pretty --require features
rerun: <%= rerun_opts %> --format junit --out junit_format_rerun --format html --out rerun.html --format rerun --out rerun.txt --no-source --require features
core: <%= standart_opts %> --tags @core
jenkins: <%= standart_opts %> --tags @jenkins
所以这里发生的是我运行黄瓜。在初始运行期间,它会将所有失败的方案抛出到rerun.txt文件中。然后,之后,我将使用以下命令重新运行失败的测试:
cucumber -p rerun
唯一的缺点是它需要一个额外的命令(当然你可以自动执行),如果你有它们,它会使测试指标变得混乱。