我的项目中有几个JUnit 4 Selenium测试。当我通过选择右键单击测试/测试文件来单独运行它们时,它们会通过。但是当我选择右键单击project / Test时,所有测试都会失败。为什么是这样?他们的运行是以某种方式初始化的吗?
我的所有测试类都继承父类:
public abstract class TestBase extends UnitilsJUnit4 {
@TestDataSource
private DataSource dataSource;
private static ExtendedHtmlUnitDriver driver=new ExtendedHtmlUnitDriver(true);;
public IDatabaseConnection connection ;
public TestBase() {
}
@Before
public void setUp() throws SQLException, DatabaseUnitException {
driver.manage().timeouts().implicitlyWait(SeleniumConstants.IMPLICITY_WAIT, TimeUnit.SECONDS);
}
@After
public void tearDown() {
Signin.signOut(driver);
driver.removeHeader("uid");
driver.close();
}
/**
* @return the driver
*/
public ExtendedHtmlUnitDriver getDriver() {
return driver;
}
测试示例:
@Test
public void myTest() {
getDriver().findElement(By.xpath("//a[starts-with(@href,'/menu/site/search')]"));