黄瓜春季测试@ConfigurationProperties不将属性注入对象的字段

时间:2018-07-09 14:48:55

标签: java spring cucumber configurationproperty

我开发了springboot +基于黄瓜和硒的测试atuomation。 我的春季黄瓜基础设施由https://github.com/cucumber/cucumber-jvm/tree/master/spring组成。

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = "json:out/cucumber.json",
    features = {"classpath:features"},
    glue = {"my.package"})
public class SeleniumCukes{}

我的财产类别是

@Data
@Configuration
@ConfigurationProperties(prefix = "application")
public class ApplicationProperty {
    private String baseUrl;
}

我的application.yml是

application:
   base-url: https://www.google.com/

我的步骤定义是

public class SomeStep{
   @Autowired
   private SomePage somePage;

   @Autowired
   private ApplicationProperty applicationProperty;

   @Given("^Go to Some Page$")
   public void catalogUserIsOnTheLoginPage() throws Throwable {
       somePage.navigateTo("some url");
       applicationProperty.getBaseUrl(); //Cucumber spring do not inject configuration property here.
   }
   ...etc
}

当我使用@SpringBootTest注释步骤定义

@SpringBootTest
public class SomeStep{
   @Autowired
   private SomePage somePage;

   @Autowired
   private ApplicationProperty applicationProperty;

   @Given("^Go to Some Page$")
   public void catalogUserIsOnTheLoginPage() throws Throwable {
       somePage.navigateTo("some url");
       applicationProperty.getBaseUrl(); //Cucumber spring do inject configuration property here.
   }
   ...etc

}

现在spring注入了应用程序属性,但是IntelliJ给我一个错误: 无法自动接线。找不到类型为bean的“ somePage”。

依赖性为:

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.seleniumhq.selenium:selenium-server:3.13.0')
    compile('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('io.cucumber:cucumber-java:2.4.0')
    testCompile('io.cucumber:cucumber-junit:2.4.0')
    testCompile('io.cucumber:cucumber-spring:2.4.0')
    testCompile('org.springframework:spring-tx')

} 春季启动版本为2.0.3.RELEASE

0 个答案:

没有答案