我设计了一个框架,其中有Base Class
设置浏览器
public class BasePage{
public WebDriver driver;
@BeforeClass
//opens the browser before each class is executed
public void setBrowser() {
driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
}
//closes the browser after each class is executed
@AfterClass
public void closeBrowser() {
driver.quit();
}
}
所有TC(例如A, B
)都继承此Base Class
,打开浏览器并执行操作。对于Ex:
public class A extends BasePage{
//Login to the application
@Test
public void fun1()
{
LoginLogout lp=new LoginLogout(driver);
lp.login(driver);
}
}
public class B extends BasePage{
//Login to the application
@Test
public void fun1()
{
LoginLogout lp=new LoginLogout(driver);
lp.login(driver);
}
}
现在在运行测试用例时:当A类正在执行时,如果我关闭浏览器,即使B类也没有运行。如果执行正常,那么对于每个类浏览器都会正确打开和关闭。