简体   繁体   中英

How can I run cucumber without any feature file?

I'm building an automation framework using Cucumber for BDD, JUnit and Selenium, we have a testrail instance in the cloud for test management and I implemented the testrail API for getting all the test cases from there, the problem is I'm not able to run these steps for getting the test cases because cucumber always validate first feature file exist.

I've tried with @Before (Cucumber) , @BeforeClass (JUnit) and the result is always the same:

No features found at [classpath:features] 0 Scenarios 0 Steps 0m0.019s

This is the main class starting the process:

 import cucumber.api.CucumberOptions;
 import cucumber.api.java.Before;
 import cucumber.api.junit.Cucumber;
 import org.apache.log4j.Logger;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;

 import static 
 com.mps.framework.support.support.Property.BROWSER_NAME;


 @RunWith(Cucumber.class)
 @CucumberOptions(
    plugin = "json:target/cucumber.json",
    features = {"classpath:features"},
    glue = {"com.selenium.test.stepdefinitions", "com.mps.selenium.hook"},
    tags = {"not @ignore"})


 public class SeleniumCukes {

private static final Logger LOG = Logger.getLogger(SeleniumCukes.class);

    @BeforeClass
    public static void startSelenium() {
     LOG.info("### Starting Selenium " + 
     BROWSER_NAME.toString().toUpperCase() + " ###");
    }

    @AfterClass
    public static void stopSelenium() {
     LOG.info("### Stopping Selenium ###");
     }
 }

This is the hooks class:

 import com.mps.selenium.base.SeleniumBase;
 import cucumber.api.Scenario;
 import cucumber.api.java.After;
 import cucumber.api.java.Before;
 import org.springframework.beans.factory.annotation.Autowired;

 import static com.mps.framework.support.hook.Hooks.hookAfter;
 import static com.mps.framework.support.hook.Hooks.hookBefore;

 public class Hooks {

   @Autowired
   private SeleniumBase seleniumBase;

   @After
   public void after() {
     hookAfter(seleniumBase.getDriver());
   }

   @Before
   public void before(Scenario scenario) {
     hookBefore(scenario);
   }
}

我不确定您要实现的目标,但它认为您正在寻找的是@BeforeSuite批注(使用import注解@BeforeSuite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM