java - 如何从 Excel 文件中获取 @tag 到 Selenium java 中的 CucumberOptions
问题描述
通常我会写一个黄瓜选项如下:
@CucumberOptions(
features = "src\\main\\java\\feature"
, glue= "stepdefination",
plugin= {"com.cucumber.listener.ExtentCucumberFormatter:Report/Report.html"}
tags="@tag, @tag1, @sort"
)
公共类 TestRunner 扩展 TestFunction {
@Test
public void runcukes( ) {
new TestNGCucumberRunner(getClass()).runCukes();
}
@BeforeClass
public void tags() {
}
@AfterClass
public void writeExtentReport() {
Reporter.loadXMLConfig("extent-config.xml");
}
}
我的问题是:如何从 excel 文件中获取 @tag、@tag1、@sort 到 @cucmberoptions 并在 Selenium Java 中运行程序?
解决方案
我不确定是否使用黄瓜选项,但通过使用黄瓜RuntimeOptions
类你可以实现它。下面的方法需要在循环中调用,这意味着您有 10 个标签要执行,然后在for
循环中调用此方法。
public static boolean cucumberRun(String tag) {
try {
ClassLoader classLoader = CustomClass.class.getClassLoader();
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
/* Adding cucumber plugins */
List<String> pluginList = new ArrayList<String>();
pluginList.add("--plugin");
pluginList.add("html:target/cucumber-html-report");
pluginList.add("--plugin");
pluginList.add("json:target/cucumber.json");
pluginList.add("--plugin");
pluginList.add("com.cucumber.listener.ExtentCucumberFormatter:");
pluginList.add("--plugin");
pluginList.add("rerun:target/failedScenarios.txt");
/* Location for BDD extent report. */
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("location/Extent_report.html");
/*
* Adding cucumberOptions.
*
* You can get the tag value from excel and pass it here. We need to add @ before tag value.
*/
RuntimeOptions ro = new RuntimeOptions(pluginList);
ro.getFilters().add("@"+tag);
ro.getFeaturePaths().add("location of feature files");
ro.getGlue().add("location of glue code");
/* Loads all the resources into Cucumber RunTime class and execute. */
cucumber.runtime.Runtime runtime = new cucumber.runtime.Runtime(resourceLoader, classFinder, classLoader,
ro);
runtime.run();
}catch(Exception e){
// Handle exception
}
推荐阅读
- javascript - 有人可以用外行的方式向我解释这个折叠示例吗?
- swift - 如何在 Swift 中为仅部分矩阵可训练的 Tensorflow 创建卷积过滤器?
- python - Python 3.x Pycharm 下的空白打印,但 Atom 下的结果
- elasticsearch - Logstash:从 inout 或 putput 部分触发 python 脚本
- javascript - 我需要事务字段的文本作为通过 portlet 构建的 NetSuite 保存搜索中的变量
- javascript - 如何为我的 Javascript 代码添加平滑过渡?
- collections - 是否可以收集迭代器以向后填充集合?
- spring-boot - 无法使用 Spring 和 JPA 从 postgres 返回数据
- sql - 从 Teradata 中位置变化的字段中提取 ID(数字)
- android - 在android studio中向微调器填充数据时出错