簡體   English   中英

如何將 @tag 從 excel 文件獲取到 Selenium 中的 CucumberOptions java

[英]How to get @tag from an excel file to CucumberOptions in Selenium java

通常我會寫一個 cucumber 選項如下:

@CucumberOptions(
        features = "src\\main\\java\\feature"
            , glue= "stepdefination",
            plugin= {"com.cucumber.listener.ExtentCucumberFormatter:Report/Report.html"}
            tags="@tag, @tag1, @sort" 
           )

公共 class 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 中運行程序?

我不確定是否使用 cucumber 選項,但通過使用 cucumber RuntimeOptions class 你可以實現它。 下面的方法需要在循環中調用,這意味着您有 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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM