【问题标题】:Xunit not closing Selenium webdriver on test fail despite using driver.Quit();尽管使用了 driver.Quit(),Xunit 没有在测试失败时关闭 Selenium webdriver;
【发布时间】:2016-12-31 05:12:49
【问题描述】:

我正在尝试将我的 Selenium Nunit 测试转换为 Xunit,但我一直无法确定驱动程序退出。

Xunit 仅在测试失败时才关闭 Selenium webdriver 进程或 chrome 浏览器,尽管使用了 driver.Quit();。

测试看起来像这样

  [Fact]
        public void test1()
        {
            SetupTest();
//testing something that fails
            TeardownTest();
        }

安装测试

 internal static void SetupTest()
        {
            driver = new ChromeDriver();
            verificationErrors = new StringBuilder();
            driver.Navigate().GoToUrl(baseUrl); 
            driver.Manage().Window.Maximize(); 
        }

拆解测试

internal static void TeardownTest()
{
    try
    {
        driver.Quit();
    }
    catch (Exception)
    {
        // Ignore errors if unable to close the browser
    }
    Assert.Equal("", verificationErrors.ToString());
}

【问题讨论】:

    标签: c# selenium selenium-chromedriver xunit


    【解决方案1】:

    您可以使用try...finally构造或实现IDisposable接口并在Dispose()中调用TeardownTest方法

    [Fact]
    public void test1()
    {
        try{
            SetupTest();
            //testing something that fails
        }finally{
            TeardownTest();
        }
    }       
    

    【讨论】:

    • 如何最小化chroom网页以获取pagesource?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多