【问题标题】:How can I run cucumber without any feature file?如何在没有任何功能文件的情况下运行黄瓜?
【发布时间】:2019-05-13 20:59:47
【问题描述】:

我正在使用 Cucumber 为 BDD、JUnit 和 Selenium 构建一个自动化框架,我们在云中有一个用于测试管理的测试轨实例,我实现了测试轨 API 以从那里获取所有测试用例,问题是我' m 无法运行这些步骤来获取测试用例,因为cucumber 始终验证第一个功能文件是否存在。

我试过@Before (Cucumber)@BeforeClass (JUnit),结果总是一样的:

在 [classpath:features] 中未找到任何功能 0 场景 0 步 0m0.019s

这是启动进程的主类:

 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 ###");
     }
 }

这是钩子类:

 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);
   }
}

【问题讨论】:

  • 对不起,我没有完全得到你的陈述。但是你能建议一下,你到底想在跑步者和钩子之间实现什么。
  • 测试用例是指特征文件吗?如果你使用 maven,你可以使用exec-maven-plugin 在类似generate-test-resources 的阶段运行一个简单的Java 程序。该程序会将特性文件从 testrail 复制到黄瓜的正确位置。

标签: java cucumber hook cucumber-jvm cucumber-java


【解决方案1】:

我不确定您要实现什么,但它认为您正在寻找的是注释 @BeforeSuite(使用 import annotations.BeforeSuite)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    相关资源
    最近更新 更多