當開始我的Cucumber測試(通過Selenium和集成/休息)時,Spring Boot(測試)應用程序不會自動啓動。黃瓜測試不啓動Spring啓動應用程序
如何配置Cucumber啓動Spring Boot應用程序(以及)?
我嘗試了很多方法。我的文件是:
黃瓜主要首發:
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumber_integration_tests")
public class Cucumber_Integration_Test {
}
膠水代碼文件是一樣的東西:
@SpringBootTest(properties = "server.port=8080", classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class wine_Cucumber_Selenium_Steps {
private WebDriver driver;
private String baseUrl = "http://localhost";
private int port = 8080;
@Given("^I visit the wine cellar home page$")
public void goToWineCellarHomePage() {
// Firefox
// System.setProperty("webdriver.gecko.driver", "K:\\k_schijf\\download_via_firefox\\geckodriver-v0.11.1-win64\\geckodriver.exe");
// driver = new FirefoxDriver();
// Chrome
System.setProperty("webdriver.chrome.driver", "K:\\k_schijf\\download_via_firefox\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl += ":" + port;
driver.navigate().to(baseUrl + "/index.html");
}
:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@IntegrationTest
public class StepDefsIntegrationTest extends SpringIntegrationTest {
@When("^the client calls /version$")
public void the_client_issues_GET_version() throws Throwable {
executeGet("http://localhost:8080/version");
}
etc.
}
開始在膠水代碼文件的應用程序的替代方法
診斷:
- 我沒有看到春天開始的消息
- 我得到錯誤信息 「ResourceAccessException:I/O錯誤的GET請求」 http://localhost:8080/version 「:連接被拒絕」
感謝您分享您的代碼。我試圖把ContextConfiguration/SpringBoot放在Cucumber runtest上,但它還沒有工作。 你有一個工作黃瓜,硒,春季啓動例子? – tjm1706
當我使用\ @SpringBootTest註釋將\ @ContextConfiguration添加到黃瓜定義的步驟之外時,您的解決方案就可以工作了! 它甚至在做黃瓜,硒,春季靴子測試時有效! 當(除了跑步測試以外),它不起作用。 – tjm1706