Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
974 views
in Technique[技术] by (71.8m points)

selenium - How to run cucumber feature file from java code not from JUnit Runner

I want to run cucumber feature file from java code.

currently we are running form JUnit Runner

package com.compareglobalgroup.testscript;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
        "com.compareglobalgroup.cucumber.hooks" }, plugin = {
                "json:cucumberreport/json/cucumberreport.json" }, tags = { ""
                        + "@Test" })
    public class TestRunnerBB extends AbstractTestNGCucumberTests {

}

I don't want to use this instead I want to run this using java program because I want to pass tags at run time from command line or jenkins.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Call the static main method of Main class in the package cucumber.api.cli that corresponds to running cucumber from the command line.

public static void main(String[] args) throws Throwable {

    Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});

          // My stepdefinition is inside java package at cucumber.sample.test
          // My feature file is inside src/test/resources/features/featurefile.feature

        } 

For additional parameters like tags or plugin use "-t","@Tags". Important the feature file path has to be the last option.

BTW - In the your example you are running with a TestNG cucumber runner.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...