【问题标题】:CucumberJS and Selenium Webdriver - Run same steps with different inputsCucumberJS 和 Selenium Webdriver - 使用不同的输入运行相同的步骤
【发布时间】:2020-04-29 11:09:42
【问题描述】:

我从 Cucumber 和 Selenium 开始。

我创建了一个测试用例,其中 selenium 运行一个表单并输入默认值,然后单击默认按钮,我们称之为test case 1,但现在我需要test case 2,我应该在其中运行相同的步骤,但使用不同的输入,想象一下:

我有一个可以选择的表单,如果用户是 男性女性,根据点击的按钮,我的表单会发生变化,所以如果我选择男性,例如,我会收到一个输入询问我是否“高”(只是一个示例),但如果我选择 Female,我会收到一个输入询问“我有男朋友”。根据我在表单上的旅程,最终结果会有所不同,考虑到这一点:

如何在不重复代码的情况下创建多个测试用例来测试每个选项?

例子:

Test case A: Male Input

Test case B: Female Input

我需要测试用例 A 来完成表单,然后执行测试用例 B,记住我的表单在两种情况下的输入都是相同的,所以我将不得不多次使用相同的输入:

Scenario A:
  Given I have to choose Male or Female
  When I click ('one of them')
  Then I will click other stuff

这甚至可能吗?

【问题讨论】:

    标签: node.js selenium selenium-webdriver cucumber cucumberjs


    【解决方案1】:

    欢迎来到 Stackoverflow!

    场景大纲最适合您的场景。

    Scenario Outline: Validate Selection
      Given I am in the required page
      When I selection <choice> from the option
      Then I will click other stuff
    
    Examples:
    |choice|
    |Male  |
    |Female|
    

    这里的文档中的最佳示例。 Link

    Scenario Outline: eating
      Given there are <start> cucumbers
      When I eat <eat> cucumbers
      Then I should have <left> cucumbers
    
      Examples:
        | start | eat | left |
        |    12 |   5 |    7 |
        |    20 |   5 |   15 |
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      相关资源
      最近更新 更多