当前位置: 首页 > 知识库问答 >
问题:

如何在Cucumber中多次运行相同的场景而不使用大纲?

闻飞跃
2023-03-14
Scenario Outline: Execute a template
 Given I have a <template>
 when I execute the template
 Then the result should be successful.
 Examples:
   | template  |
   | templateA |  
   | templateB |  

这种方法的优点是,每当我添加一个新模板时,我就不需要更新特性测试。

谢谢

共有1个答案

葛泳
2023-03-14

是的,将模板列表放在步骤定义中,或者更好地放在应用程序中。然后你可以写

  Scenario: Execute all templates
    When I execute all the templates
    Then there should get no errors

有趣的是如何实现这一点。类似于:

module TemplateStepHelper
  def all_templates
    # either list all the templates here, or better still call a method in 
    # the app to get them
    ...
  end
end
World TemplateStepHelper

When "I execute all the templates" do
  @errors = []
  all_templates.each do |t|
    res = t.execute
    @errors << res unless res
  end
end

Then "there should be no errors" do
  expect(@errors).to be_empty
end

代码的确切细节可以修改以满足您的需要。

 类似资料:
  • 在我的cucumber jvm项目中,我希望在不使用场景大纲的情况下,使用相同的数据集执行场景10次(数据在excel中提供)。 有人能指导我如何做到这一点吗?

  • 我的cucumber小cucumber看起来像这样: 在上面的功能中,有一个背景,它将为两个场景大纲中的每个示例执行。此外,在java实现中,我们已经实现了@After和@Before钩子,它们也将针对每个示例执行。 我们正在使用spring Cumber进行步骤之间的数据注入。 当第一个场景大纲中的所有示例结束时,调用@After实现的方法两次,就会出现问题。当第二次@After同时启动时,第二

  • jhbhhjhj当我点击登录并输入有效的“kumar.rakesh@yopmail.com”和有效的“admin@123”,然后点击登录,用户应该可以成功登录 测试转轮

  • cucumber中的多个标签不会运行这些场景。 我有两个不同的标签,在同一个功能文件下标记为两个不同的场景。我尝试使用cucumber tages命令运行标记的两个场景 cucumber--标签@计费--标签@重要 当我运行这个时,cucumber不识别场景,它提供如下输出 但是当我单独运行标签时,比如< code>cucumber - t @billing,cucumber能够识别并运行这个场景

  • 真希望有人能帮上忙。 在cucumber的“示例”中是否可以使用两个不同的外部数据文件?如下所示: @play_movie 场景概述:在网站上播放视频 在这个场景中有一个数据文件,但是如果我想在这个场景中使用两个或更多不同的数据文件呢。有可能用cucumber做吗? 我使用Java作为编码语言。 谢谢

  • 大家好,如果有人能帮忙的话——我正在尝试使用Cucumber标签运行一个特定的场景——这是我用来运行用Webdriver-Cucumber框架构建的测试的表达式- npx wdio运行wdio。conf.js——cucumber。tagExpression='@Tag 当我使用上面的命令时,什么也不会发生——我已经在功能级别定义了标记-“@tag”——所以我希望功能文件中的所有场景都会得到执行,但