我有一个父网页测试,由测试类调用,如下所示:
public class Webtest
{
protected static WebDriver driver;
@BeforeMethod
public static WebDriver openUrl(String URL)
{
driver = new FirefoxDriver();
driver.get(URL);
System.out.println("Driver started :"+ driver);
return driver;
}
public static WebDriver closeDriver(){
driver.quit();
System.out.println("Driver closed :"+ driver);
}
}
现在我在扩展它的测试类中实现上述内容。
public class testClass extends WebTest
{
@Test
public void TC01()
{ System.out.println("Test1:" + driver);
// Do something using driver
}
@Test
public void TC02()
{
System.out.println("Test2:" + driver);
// Do something
}
}
现在结果:
Driver started :FirefoxDriver: firefox on MAC (dfe4e055-4555-0d4d-8a83-a9a802159ea7)
Test1:FirefoxDriver: firefox on MAC (dfe4e055-4555-0d4d-8a83-a9a802159ea7)
Driver closed :FirefoxDriver: firefox on MAC (dfe4e055-4555-0d4d-8a83-a9a802159ea7)
Driver started :FirefoxDriver: firefox on MAC (1370df47-483b-574c-9792-9bb5fa077364)
Test2:FirefoxDriver: firefox on MAC (1370df47-483b-574c-9792-9bb5fa077364)
[Error] resulted in an exception: The FirefoxDriver cannot be used after quit() was called.
基本上,我假设test2正在使用以前的驱动程序。我没有调用第二个驱动程序退出但是我收到了错误。我确实把睡眠放在每种方法之间,并尝试但没有任何效果。有帮助吗?我正在使用firefox 46。