這是我目前使用的過程取決於你想用你可以爲它創建不同的豆類網絡驅動器的一個片段。 確保你有你的pom.xml
春天開機測試和硒:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
在我的情況${selenium.version}
是:
<properties>
<selenium.version>2.53.1</selenium.version>
</properties>
,而這些都是類:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Import(IntegrationConfiguration.class)
public abstract class AbstractSystemIntegrationTest {
@LocalServerPort
protected int serverPort;
@Autowired
protected WebDriver driver;
public String getCompleteLocalUrl(String path) {
return "http://localhost:" + serverPort + path;
}
}
public class IntegrationConfiguration {
@Bean
private WebDriver htmlUnitWebDriver(Environment env) {
return new HtmlUnitDriver(true);
}
}
public class MyWhateverIT extends AbstractSystemIntegrationTest {
@Test
public void myTest() {
driver.get(getCompleteLocalUrl("/whatever-path/you/can/have"));
WebElement title = driver.findElement(By.id("title-id"));
Assert.assertThat(title, is(notNullValue()));
}
}
希望它有助於!
你能看到日誌中的任何異常/消息嗎? –