黄瓜:如何从外部Excel文件中读取场景概述示例

时间:2018-11-07 16:37:07

标签: cucumber bdd cucumber-jvm gherkin cucumber-java

我的要求是从外部excel文件中读取示例,而不是将其硬编码到功能文件中。我有100多个示例,这些示例很难在功能文件中维护。您能帮我吗?

这是我的情况-

Scenario Outline: Browser Test

    When I visit the URL <base>/<page>/<ordNumber>/<custName>
    Then the browser contains test <custNumber>

    Examples: 
     | base                         | page   | ordNumber | custName |
     | http://www.stackoverflow.com | orders | 123       | John     |
     | http://www.stackoverflow.com | orders | 456       | Mike     |
     | http://www.stackoverflow.com | orders | 789       | Tom      |

我想用示例数据创建一个excel文件并在运行时加载

examples.xls

 | base                         | page   | ordNumber | custName |
 | http://www.stackoverflow.com | orders | 123       | John     |
 | http://www.stackoverflow.com | orders | 456       | Mike     |
 | http://www.stackoverflow.com | orders | 789       | Tom      |

谢谢。

2 个答案:

答案 0 :(得分:0)

在这种情况下,我会选择基于模板和使用模板引擎(例如Velocity)来生成功能文件。

要与Excel集成,可以使用 POI 库正确读取* .xls文件。

然后像使用“硬编码”文件那样运行生成的特征文件。

希望这会有所帮助!

答案 1 :(得分:0)

使用gherkin with QAF支持您要查找的内容。 QAF支持不同的外部data providers,包括json,xml,csv,excel和DB。它还支持multiple bdd syntax

下面结合使用带有QAF的Gherkin或BDD2:

onFormSubmit() {
  const result = this.patientForm.value;
  result.date_of_birth = moment(result.date_of_birth).format('YYYY-MM-DD');
  this.serviceName.addUser(result).subscribe();
}

资源管理,执行配置,驱动程序管理和并行执行还有很多其他功能。

相关问题