2017-02-23 49 views
0

我有一個使用黃瓜和硒測試設置的彈簧引導應用程序。我正在嘗試創建一個用於運行我的黃瓜測試場景的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 = {"[email protected]"}) 
    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類來爲空。

回答

0

試試這個:

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