簡體   English   中英

Selenium WebDriver測試(Java)后無法關閉Firefox窗口

[英]Cannot close Firefox window after Selenium WebDriver test (Java)

我知道這里還有其他一些類似的問題,但是我通讀了它們,無法解決我的問題。 我也不完全精通JUNIT批注等,所以這也使我感到困惑。 這就是我所擁有的,我只希望在成功(或失敗)測試后關閉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();
}
}

在此先感謝您,你們是最棒的。 如果相關,我可以提供我的pom.xml。

您正在混合舊的和新的JUnit。 這就是為什么它不起作用。 您有兩種方法可以解決此問題:

  1. 舊方法:刪除注釋,然后將closeWindow()重命名為tearDown() 這將覆蓋TestCase的相應功能。
  2. 新方法:不要擴展TestCase 然后,將使用批注並調用closeWindow()方法。

您的setUp()函數已經覆蓋了TestCase的相應函數,這就是該部分起作用的原因。 但是, TestCase不知道closeWindow() ,並且如果擴展了TestCase ,則JUnit似乎會使用其他TestCase程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM