通过黄瓜步骤定义类获取应用程序属性

问题描述 投票:0回答:2

我有一个春季启动应用程序与黄瓜和硒测试设置。我正在尝试创建一个用于运行我的黄瓜测试场景的UI包装器。我需要运行我正在使用cucumber.api.cli.Main.run方法的选定功能文件。问题是我试图通过我的application.yml文件选择属性,但我的步骤定义类无法选择属性。

这就是我的代码的样子 -

RunCukes类

    @RunWith(Cucumber.class)
    @CucumberOptions(features = {"classpath:features"}, 
    plugin = { "pretty", "html:target/cucumber-html-report","json:target/cucumber.json" }, 
    tags = {"~@ignore"})
    public class RunCukesTest {
    }

运行黄瓜特征文件的类

      @Service
      public class SeleniumLogic {

      @Autowired
      RunCukesTest runCukes;

        public byte runTest(String[] argv) throws IOException{
            byte result = cucumber.api.cli.Main.run(argv,runCukes.getClass().getClassLoader());
            return result;
           }
         }

stepdefinition类

        @Component
        public class LoginTestSteps {
          @Autowired
          private LoginPage loginPage;

          @Value("${host.name}")
          private String HOST_NAME;

          @Given("^User is on the login page$")
          public void user_is_on_the_login_page() throws Throwable {
            loginPage.load(HOST_NAME);
          }
       }

Application.yml

     host:
       name: abc.com

HOST_NAME在LoginTestSteps类中显示为null。

java selenium spring-boot cucumber-java
2个回答
0
投票

试试这个:

 @Component
 @PropertySource("classpath:application.properties")
 public class LoginTestSteps {

0
投票

遇到同样的问题,我的结论是不可能这样做。 application.yml是Spring的配置文件,因此在使用Cucumber项目时,您必须执行自己的配置文件格式并从中读取。你可以有一个

@Value("${host.name:abc.com}")

因此abc.com是您的默认设置,并且您可以在使用a运行项目时覆盖它

java -jar -Dhost.name=myotherurl.com pathToYourJar/myJar.jar
© www.soinside.com 2019 - 2024. All rights reserved.