如果测试用例失败,Selenium Web驱动程序无法关闭firefox实例 [英] Selenium web driver not able to close firefox instance if a Test cases is failed

查看:381
本文介绍了如果测试用例失败,Selenium Web驱动程序无法关闭firefox实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我伙计,
我正在使用junit和selenium web driver 2.28。
问题是如果我运行一个成功的测试用例,web驱动器能够关闭firefox实例,但是当测试用例失败时,selenium web驱动程序无法关闭firefox。
我使用的是带有selenium-server-standalone-2.28.0.jar的FF 15.0.1。
请回复
谢谢
Sahil

i folks, i am using junit with selenium web driver 2.28. the problem is if i run a successful test case the web drives is able to close the firefox instance, but when a test case fails the selenium web driver is not able to close the firefox. i am using FF 15.0.1 with selenium-server-standalone-2.28.0.jar. please respond thanks Sahil

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;
}


推荐答案

添加 webdriver.quit() @AfterClass 方法

示例我正在使用 selenide 4.5 我必须添加(根据此版本)
没有关闭或处置此依赖关系

Example Am using selenide 4.5 i had to add (according to this version ) no close or dispose there for this dependency

import static com.codeborne.selenide.WebDriverRunner.getWebDriver; 

@AfterClass
public static void cleanupBrowser(){
    getWebDriver().close();
}

这篇关于如果测试用例失败,Selenium Web驱动程序无法关闭firefox实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆