cucumber-jvm - 如何使用最新的 io.cucumber.cucumber-testng 版本 4.2.6 编写自定义的 TestNGCucumberRunner
问题描述
我正在尝试编写一个自定义 TestNGCucumberRunner (对于最新版本的黄瓜 4.2.6),我可以在 getFeatures() 方法中根据运行时参数过滤 cucumberfeatures 列表。
网上所有的例子都是用 info.cukes 1.2.5 版本解释的,所有依赖的类和方法都是公开的
我以前从未写过测试运行程序。有人可以帮忙吗?
解决方案
首先 -根据 v 4.2.6 使用正确的 io.cucumber 依赖项更新 POM.xml
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.6</version>
</dependency>
第二 -根据您的框架需要自定义 TestNGRunner 类
package com.jacksparrow.automation.suite.runner;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import com.jacksparrow.automation.steps_definitions.functional.BaseSteps;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(features = "classpath:features/functional/",
glue = {"com.jacksparrow.automation.steps_definitions.functional" },
plugin = { "pretty","json:target/cucumber-json/cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
tags = { "@BAMS_Submitted_State_Guest_User" },
junit ={ "--step-notifications"},
strict = false,
dryRun = false,
monochrome = true)
public class RunCukeTest extends Hooks {
}
第三- 实现 Hooks.java
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import cucumber.api.testng.AbstractTestNGCucumberTests;
public class Hooks extends AbstractTestNGCucumberTests {
@Parameters({ "browser" })
@BeforeTest
public void setUpScenario(String browser){
BaseSteps.getInstance().getBrowserInstantiation(browser);
}
}
注意 - 我没有以这种方式实现。但据我所知,它可能会奏效。请检查并分享您的经验。
第四 -根据您的 TestNGRunner 类和框架需要更新 /src/test/resources/ 下的 TestNG.xml。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="1" name="Test" parallel="tests">
<parameter name="browser" value="chrome" />
<classes>
<class
name="com.jacksparrow.automation.suite.runner.RunCukeTest" />
</classes>
</test>
</suite>
第五 -您应准备好以下列任何方式使用 TestNG 运行自动化套件
- Run TestNG.xml directly from IDE
- From CMD - mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng.xml
- From POM.xml - Using Surefire Plugin
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
推荐阅读
- java - sftp二次开发如何使用guacamole
- python - 比较两个不同数据框的两列并使用 If 条件创建新列
- jquery - .Closest() with Classes 似乎没有选择正确的元素
- android - 在 iOS 的 UITextView 上加载 html 字体的问题
- android - 如何使用 TypeConverter 将 Joda-Time Period 字段保存到 Room 中?
- regex - Python中以下特定情况下正则表达式与字符串操作的性能比较
- python - 是否有将 jaeger 4.0.0 与 pyinstaller(python3.7) 一起使用的解决方法?
- python - 熊猫以相同的频率重新采样 - 如何复制行?
- python - 索引时如何解包元组?
- r - R当内部条件发生变化时执行循环的最快方法