[英]Cannot close Firefox window after Selenium WebDriver test (Java)
I know there are a few other similar questions on here, but I read through them and was unable to solve my issue. 我知道这里还有其他一些类似的问题,但是我通读了它们,无法解决我的问题。 I also am not entirely fluent in JUNIT annotations and the like, so that is kind of confusing me as well.
我也不完全精通JUNIT批注等,所以这也使我感到困惑。 Here is what I have, and I just want the firefox window to close after a successful (or unsuccessful) test.
这就是我所拥有的,我只希望在成功(或失败)测试后关闭Firefox窗口。
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestWorkGaps extends TestCase {
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() {
driver = (WebDriver) new FirefoxDriver();
baseUrl = "https://dev.XXX.com";
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
}
@Test
public void test() throws InterruptedException {
driver.get(baseUrl);
success = core.TestCore.checkMain(driver);
if (!success) {
fail("Main page did not load correctly.");
}
//various other tasks
success = core.LoginLogout.logout(driver);
if (!success) {
fail("Not able to logout.");
}
}
@After
public void closeWindow()
{
driver.close();
driver.quit();
}
}
Thanks in advance, you guys are the best. 在此先感谢您,你们是最棒的。 I can provide my pom.xml if it is relevant.
如果相关,我可以提供我的pom.xml。
You are mixing old and new JUnit; 您正在混合旧的和新的JUnit。 this is why it is not working.
这就是为什么它不起作用。 You have two possible ways of fixing this:
您有两种方法可以解决此问题:
closeWindow()
to tearDown()
. closeWindow()
重命名为tearDown()
。 This will override the corresponding function in TestCase
. TestCase
的相应功能。 TestCase
. TestCase
。 Then the annotations will be used and the closeWindow()
method will be called. closeWindow()
方法。 Your setUp()
function already overrides the corresponding function in TestCase
which is why that part worked. 您的
setUp()
函数已经覆盖了TestCase
的相应函数,这就是该部分起作用的原因。 The closeWindow()
however was unknown to TestCase
and it seems JUnit uses a different runner if TestCase
is extended. 但是,
TestCase
不知道closeWindow()
,并且如果扩展了TestCase
,则JUnit似乎会使用其他TestCase
程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.