|
在写一个selenium+testNg的自动化测试,HomePageTest继承BasicTest BasicTest又实现PrepareTestNG接口,然后运行测试,配置文件中只配置了<class name="HomePageTest"/>这一个,然后运行发现继承过来的beforeXXX和afterXXX都没有运行。请问该如何配置呢?
代码如下:
public interface PrepareTestNG {
@BeforeSuite
public abstract void beforeSuit();
@AfterSuite
public abstract void afterSuit();
@BeforeTest
public abstract void beforeTest();
@AfterTest
public abstract void afterTest();
@BeforeGroups
public abstract void beforeGroups();
@AfterGroups
public abstract void afterGroups();
@BeforeClass
public abstract void beforeClass();
@AfterClass
public abstract void afterClass();
@BeforeMethod
public abstract void beforeMethod();
@AfterMethod
public abstract void afterMethod();
}
public abstract class BasicTest implements PrepareTestNG {
protected WebDriver driver;
public void beforeSuit() {
}
public void afterSuit() {
}
public final void beforeTest() {
driver = new HtmlUnitDriver(true);
}
public final void afterTest() {
if (driver != null) {
driver.quit();
}
driver = null;
}
@Test
public abstract void verifyUserName();
}
public class HomePageTest extends BasicTest {
private Home homePage;
@Test
public void verifyTitle() {
Assert.assertEquals("商城首页", homePage.getTitle());
Assert.assertEquals(Url.HOME_PAGE, homePage.getUrl());
}
@Override
public void beforeGroups() {
}
@Override
public void afterGroups() {
}
@Override
public void beforeClass() {
driver.get(Url.HOME_PAGE);
homePage = new Home(driver);
}
@Override
public void afterClass() {
homePage = null;
}
@Override
public void beforeMethod() {
}
@Override
public void afterMethod() {
}
@Override
public void verifyUserName() {
Assert.assertEquals("nobody", homePage.getUserName());
}
}
|
|