简体   繁体   English

Selenium WebDriver测试(Java)后无法关闭Firefox窗口

[英]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: 您有两种方法可以解决此问题:

  1. The old way: remove the annotations and rename closeWindow() to tearDown() . 旧方法:删除注释,然后将closeWindow()重命名为tearDown() This will override the corresponding function in TestCase . 这将覆盖TestCase的相应功能。
  2. The new way: don't extend 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.

相关问题 Selenium Webdriver-如何使用Java关闭弹出窗口 - Selenium Webdriver - How to close popup window with java 在 Z93F725A07423FE1C889F448B33D21F 中使用 selenium 关闭所有 window firefox - close all window firefox using selenium in java? 使用相同的Firefox窗口在Selenium WebDriver(Java)中运行多个测试 - Using the same Firefox Window to run multiple tests in Selenium WebDriver (Java) 如何使用 Selenium WebDriver 和 Java 关闭特定的 window? - How can I close a specific window using Selenium WebDriver with Java? 如何使用Selenium WebDriver处理Firefox上载文件窗口-Java - How to handle Firefox Upload File window with Selenium WebDriver - Java 如何使用Java关闭Selenium WebDriver中的子浏览器窗口 - How to close child browser window in Selenium WebDriver using Java Selenium IE WebDriver在测试后无法关闭/退出 - Selenium IE WebDriver doesn't close/quit after test 如何让webdriver在每次测试后都不关闭浏览器窗口? - How make webdriver not to close browser window after each test? 无法在没有UI的框中以Java启动selenium.WebDriver firefox - cannot start selenium.WebDriver firefox in java in a box with no UI 使用GeckoDriver运行Java Selenium WebDriver时,Firefox无法连接 - Firefox Cannot Connect When Running Java Selenium WebDriver With GeckoDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM