2

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

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

我正在使用 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);
}
4

5 回答 5

1

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

于 2010-08-16T23:52:29.657 回答
1

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

高温高压

于 2012-02-29T23:34:18.623 回答
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();
}
于 2014-03-27T09:13:30.977 回答
0

ie.close() 在 ie 8 中为我工作

于 2010-07-22T22:59:00.213 回答
0

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

于 2010-08-04T20:56:10.547 回答