如何将特定的Java文件与黄瓜中的特定功能文件匹配 [英] How to match a specific java file with specific feature file in cucumber

查看:86
本文介绍了如何将特定的Java文件与黄瓜中的特定功能文件匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在黄瓜中创建了三个Java和功能文件,每个Java文件都有以下代码部分。

I've created three java and feature files within cucumber and there's following code part for each java file.

@Before
public void startbrowser() {
 System.setProperty("webdriver.gecko.driver","/Users/firatkaymaz/eclipse-workspace/SeleniumTest/drivers/geckodriver/geckodriver");
 driver = new FirefoxDriver();

所以一旦我尝试运行我的一个黄瓜文件(以-> cucumber功能运行),三个浏览器正在打开,因为位于三个Java文件中的所有@Before注释都正在执行。我该如何摆脱呢?我想将名为TestCase1.feature的功能文件与Case1.java匹配,因此当我执行相关功能文件时,将执行Case1,因此只能按预期打开一个浏览器。知道吗?

so once i try to run one of my cucumber files (run as ->cucumber feature), three browser is opening because all @Before annotations located in three java file are being executed. how can i get rid of that ? I want to match the feature file named TestCase1.feature with Case1.java so when i execute concerned feature file, Case1 is gonna be executed so just one browser can be opened as expected. any idea ?

文件

推荐答案

另一种方法是对类使用@ScenarioScoped批注。您需要在pom文件中添加
cucumber-guice

然后可以将此注释添加到创建驱动程序的类中,并且在整个场景中将只有一个实例。
http://www.thinkcode.se/blog/2017/08/16/sharing-state-between-steps-in-cucumberjvm-using-guice

An alternative approach is to use the @ScenarioScoped annotation for a class. You need to add cucumber-guice to your pom file or whatever. Then you can add this annotation to the class your driver is created by and there will be single instance of it for the whole scenario. http://www.thinkcode.se/blog/2017/08/16/sharing-state-between-steps-in-cucumberjvm-using-guice

这篇关于如何将特定的Java文件与黄瓜中的特定功能文件匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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