4

皆さん、selenium Webドライバー2.28でjunitを使用しています。問題は、成功したテスト ケースを実行した場合、Web ドライブは Firefox インスタンスを閉じることができますが、テスト ケースが失敗した場合、Selenium Web ドライバーは Firefox を閉じることができないことです。私は selenium-server-standalone-2.28.0.jar で FF 15.0.1 を使用しています。返信してください ありがとう

private void startWebdriver() throws UIException{
    //2) Prevent re-use.
    if(UIHandlerWD.this.profile == null)
        throw new 
            UIException(
                UIException.Code.UI, 
                    "Webdriver instance cannot be instantiated."
            );              

    //3) Configure Selenium Webdriver.
    if (this.profile.browserType.equalsIgnoreCase("*firefox")){
        FirefoxProfile fProfile = new FirefoxProfile();

       // profile.SetPreference("network.http.phishy-userpass-length", 255);
        fProfile.setAcceptUntrustedCertificates(true);
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setJavascriptEnabled(true);
        dc.setCapability(FirefoxDriver.PROFILE, fProfile);

        //this.webdriver = new FirefoxDriver(dc);
        this.webdriver = new FirefoxDriver(dc);
    }
    else if (this.profile.browserType=="INTERNETEXPLORER")
        this.webdriver = new InternetExplorerDriver();
    else
        throw new 
        UIException(
            UIException.Code.UI, 
                "Unknown browser type '" + this.profile.browserType +"'."
        );          


    //4) Start Webdriver.
    this.webdriver.get(this.profile.getURL().toString());
    this.webdriver.manage().timeouts().
    implicitlyWait(5, TimeUnit.SECONDS);
    this.webdriver.manage().timeouts().
    pageLoadTimeout(this.profile.timeout, TimeUnit.SECONDS);

}

void stopWebdriver() {
    if(this.webdriver != null){
        try{
        Thread.sleep(5000);
        }
    catch (Exception e) {
        // TODO: handle exception
    }
        this.webdriver.close();
    }
    this.webdriver = null;
    this.profile = null;
}
4

1 に答える 1

19

メソッドに追加webdriver.quit()@AfterClassます。

close() は、現在アクティブなウィンドウを閉じます。現在アクティブなウィンドウが最後のウィンドウである場合、quit() を実行するのと機能的に同等です。

ただし、これを行うには、有効なアクティブ セッションが必要です。テストが失敗した場合、そのセッションはおそらく停止しているため、close() を呼び出すと、コマンドの送信先がわからず、例外がスローされます。

quit() はすべてのセッションを終了し、すべてのクライアントをシャットダウンします。これは基本的にすべてをクリーンアップするコマンドです。また、すべてのクライアント/セッションがすでに閉じられている/終了している場合、例外はスローされません。

于 2013-02-04T22:06:54.863 に答える