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

查看:18
本文介绍了Scenrio 大纲的设置和拆卸 (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 场景大纲就是这样!有没有办法在 cucumber-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)

推荐答案

据我所知没有直接的方法,但是您可以标记您的场景并使用标记的 before 和 after 挂钩作为解决方法.

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 大纲的设置和拆卸 (cucumber-jvm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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