Scenrio大纲的setUp和tearDown(cucumber-jvm) [英] setUp and tearDown for Scenrio outline (cucumber-jvm)

查看:162
本文介绍了Scenrio大纲的setUp和tearDown(cucumber-jvm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用了方案大纲,想在方案大纲开始之前执行一些代码,并在方案大纲执行完成之后执行一些代码。

I'm using scenario outline in my code and wanted to execute some code before the start of scenario outline and some code after the scenario outline execution has completed.

我知道有黄瓜中的@Before和@After注释,但是它们在每种情况之前和之后执行。因此,如果我有一个方案大纲和3行示例数据,那么@Before和@After将分别执行,即每次执行3次。

I know there are @Before and @After annotations in cucumber but these gets executed before and after every scenario. So if I have a scenario outline and 3 rows of example data then @Before and @After will be executed each of then i.e. total 3 times each.

但是我只想执行一次,@Before方案大纲和@After方案大纲就是这样!在cumber-jvm中有什么方法可以实现这一目标?

But I want to execute it only once, @Before scenario outline and @After scenario outline thats it! Is there any way to achieve this in cucumber-jvm?

//@Before (some code that should be executed before scenario outline execution begins)

Scenario outline
....
Examples:
|Header1  | Header2 | ..etc
|Data1    | Data2   |

//@After (some code that should be executed after scenario outline execution ends)


推荐答案

据我所知,没有直接的方法,但是您可以标记您的方案,并使用标记之前和之后的钩子作为解决方法。

As far as i know there is no direct way, but you can tag your scenario and use the before and after hooks for tags as a workaround.

下面是一个示例:

Feature: ExampleTagging
    @DoBeforeScenarioX
    Scenario outline
    ....
    Examples:
    |Header1  | Header2 | ..etc
    |Data1    | Data2   |

然后您可以在Java代码中使用它:

Then you can use this in your Java code:

@Before("@DoBeforeScenarioX")
public void do_this_before_scenarioX() {....}

@After("@DoBeforeScenarioX")
public void do_this_after_scenarioX() {....}

以下是描述的标签: https://github.com/cucumber/cucumber/wiki/Tags

这篇关于Scenrio大纲的setUp和tearDown(cucumber-jvm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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