如何在SeleniumJava中从excel文件获取@tag到cucumberoptions

20jt8wwn  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(434)

通常我会写一个cumber选项,如下所示:

@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并在SeleniumJava中运行该程序?

vmpqdwk3

vmpqdwk31#

我不确定是否要使用cucumber选项,但可以使用cucumber 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
}

相关问题