How do I close the browser (IE8) using Watin?
-
30-09-2019 - |
Question
I am using Watin 2.0 to develop some automated UI tests. I cannot get Watin to close the browser after it has opened it. The Watin.Core.Browser object implements IDisposible but Dispose() does not do the trick. I have also tried using the Close() method.
Most recently I have tried wrapping the IE object instantiation in a Using statement but no luck.
I am testing with 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);
}
Solution
It seems that if the test throws some exception the dispose is never called.
OTHER TIPS
You also want to be sure that you don't have any IE developer consoles (F12) open - it will cause WatiN 2.1 to hang when .Close() is called.
HTH
Late to the party but have you tried ForceClose():
if (ie.NativeBrowser != null)
{
ie.ForceClose();
}
Or to ensure no other instances of IE are open find all open instances and ForceClose() them:
while (IE.InternetExplorersNoWait().Count > 0)
{
var ie = IE.InternetExplorersNoWait()[0];
ie.ForceClose();
}
You can also force the Dispose() method:
if (ie.NativeBrowser != null)
{
ie.Dispose();
}
ie.close() worked for me in ie 8
Also, You might want to check your browser AutoClose
property ie.AutoClose