Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
947 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...