黄瓜示例在不同功能/场景中的重用 [英] Cucumber examples reuse in different features/scenarios

查看:146
本文介绍了黄瓜示例在不同功能/场景中的重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用黄瓜已有一段时间了,偶然发现了一个问题:

I've been using cucumber for awhile and I've stumbled upon a problem:

实际问题:

是否存在一种解决方案,可以使用黄瓜专门作为示例从单个文件/数据库导入示例? 或者,是否有一种方法可以在已经步入示例的同时定义变量? 又或者,当我启动功能文件/场景时,是否可以将示例作为变量发送?

Is there a solution to import the examples from a single file/db using cucumber specifically as examples? Or alternatively is there a way to define a variable while already in-step to be an example? Or alternatively again, is there an option to send the examples as variables when I launch the feature file/scenario?

问题:

我有几种情况,我想一遍又一遍地使用完全相同的示例.

I have a couple of scenarios where I would like to use exactly the same examples, over and over again.

听起来很容易,但是示例表非常大(更具体地说,它包含了世界上所有国家及其相应大洲的信息).因此,重复此操作将非常麻烦,尤其是在需要更改表的情况下(我将需要单独更改表的所有实例)

It sounds rather easy, but the examples table is very large (more specifically it contains all the countries in the world and their appropriate continents). Thus repeating it would be very troublesome, especially if the table needs changing (I will need to change all the instances of the table separately)

并发症:

我有一个重新运行功能,该功能可以知道特定示例何时失败,并在测试完成后重新运行它.

I have a rerun function that knows when a specific example failed and reruns it after the test is done.

限制:

我不想编辑我的重新运行文件

I do not want to edit my rerun file

相关

我注意到这里已经有一个关于从csv导入它的公开讨论: 将CSV作为测试数据导入Cucumber吗?

I've noticed that there is already an open discussion about importing it from csv here: Importing CSV as test data in Cucumber?

但是,该讨论对我来说是无效的,因为我拥有只知道仅适用于示例的重新运行功能,而该解决方案建议将其毁掉.

However that discussion is invalid to me because I have the rerun function that only knows to work only with examples, and the solution suggested there ruins that.

谢谢!

推荐答案

您可以将CSV和其他外部文件系统与 QAF 使用不同的 BDD语法.

You can use CSV and other external file systems with QAF using different BDD syntax.

如果您要使用黄瓜台阶或黄瓜浇口,可以使用 QAF黄瓜和BDD2(首选)或Gherkin语法. QAF黄瓜将启用黄瓜的外部测试数据和其他qaf功能.

If you want to use cucumber steps or cucumber runner, you can use QAF-cucumber and BDD2 (preferred) or Gherkin syntax. QAF-cucumber will enable external test data and other qaf features with cucumber.

下面是使用BDD2语法的示例功能文件,可以使用 TestNG 黄瓜运行器.

Below is the example feature file uses BDD2 syntax can be run using TestNG or Cucumber runner.

Feature: feature uses external data file

@datafie:resources/${env}/testdata.csv
@regression 
Scenario:  Another scenario exploring different combination using data-provider
    Given a "${precondition}"
    When an event occurs
    Then the outcome should "${be-captured}"   

testdata.csv 文件可能类似于:

TestcaseId,precondition,be-captured
123461,abc,be captured
123462,xyz,not be captured

您可以使用 TestNG 内置数据提供程序自定义.

You can run using TestNG or Cucumber runner. You can use any of inbuilt data provider or custom as well.

这篇关于黄瓜示例在不同功能/场景中的重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆