2017-02-13 35 views
0

第一次在这里,所以我会尽量做到最具可读性。我在使用排序一些数据的DataTable中的一个特征文件测试所看到如下:使用Ruby/Watir获取钩子文件中的黄瓜数据表

Current cucumber test example

目前我使用scenario.test_steps.map(&:name)让所有的步骤(这是因为集成到应用程序的必要阵列中的生命周期的软件管理器),这就是我得到:

Cucumber steps got in the hooks file

我的问题是:是否有可能之前做的就是在的数据表信息|场景|钩住钩子文件?

在此先感谢任何人的帮助!

回答

0

当迭代通过scenario.test_steps时,每个测试步骤都有一个关联的Cucumber::Core::Ast::Step。这包含步骤的具体信息,如步骤名称,数据表等相关Ast::Step将是测试步骤的source的最后一个元素:

test_step.source 
#=> [ 
#=> #<Cucumber::Core::Ast::Feature "Feature: Something" (features/something.feature:1)>, 
#=> #<Cucumber::Core::Ast::Scenario "Scenario: Only a test" (features/something.feature:3)>, 
#=> #<Cucumber::Core::Ast::Step "Given : the fields" (features/something.feature:4)> 
#=> ] 

要访问Ast::Step多行参数,检查multiline_arg 。如果指定了数据表,则会返回Ast::DataTable。否则,将返回Ast::EmptyMultilineArgument。通过调用data_table?可以检查返回值是否为数据表。

作为一个例子,下面将通过各测试步骤和输出的数据表,如果定义迭代:

Before do |scenario|  
    scenario.test_steps.each do |test_step| 
    multiline_arg = test_step.source.last.multiline_arg 
    puts multiline_arg.raw if multiline_arg.data_table? 
    end 
end 
+0

感谢您的答复@Justin柯。我完全按照你的说法复制和粘贴,但没有工作,所以我使用'begin rescue'模块进行了一些更改,并且_voilá_工作正常! –