如何使用Watin关闭浏览器(IE8)?

时间:2010-06-25 19:17:31

标签: c# .net unit-testing watin coded-ui-tests

我正在使用Watin 2.0开发一些自动UI测试。打开浏览器后,我无法让Watin关闭浏览器。 Watin.Core.Browser对象实现了IDisposible,但Dispose()不能解决问题。我也尝试过使用Close()方法。

最近我尝试在Using语句中包装IE对象实例化但没有运气。

我正在使用IE8进行测试

using (IE ie = new IE())
{
    ie.GoTo(ApplicationContainer.SummaryUriProvider.URI);
    Link furthurReadingLink = ie.Link(Find.ByText("Further Reading"));
    furthurReadingLink.Click();

    string subTitle = ie.Div("frheader").Element(Find.ByClass("panelsubtitle")).Text;

    Assert.AreEqual("Further Reading", subTitle);
}

5 个答案:

答案 0 :(得分:1)

似乎如果测试抛出一些异常,则永远不会调用dispose。

答案 1 :(得分:1)

您还要确保没有任何 IE开发人员控制台(F12)打开 - 当调用.Close()时,它将导致WatiN 2.1挂起。

HTH

答案 2 :(得分:1)

派对迟到但你试过ForceClose():

if (ie.NativeBrowser != null)
{
    ie.ForceClose();
}

或者为了确保没有其他IE实例打开,找到所有打开的实例和ForceClose()它们:

while (IE.InternetExplorersNoWait().Count > 0)
{
    var ie = IE.InternetExplorersNoWait()[0];
    ie.ForceClose();
}

您也可以强制使用Dispose()方法:

if (ie.NativeBrowser != null)
{
    ie.Dispose();
}

答案 3 :(得分:0)

ie.close()为我工作,即8

答案 4 :(得分:0)

此外,您可能需要检查浏览器AutoClose属性ie.AutoClose