我正在尝试WatiN为我们的UI测试,我可以得到测试工作,但我不能让IE关闭后。问题附加到IE浏览器
我试图关闭IE中的类清理代码,使用WatiN的示例IEStaticInstanceHelper technique。
这个问题似乎被附接至所述IE线程,超时:(_ieHwnd是手柄到IE当IE第一次启动存储)
_instance = IE.AttachTo<IE>(Find.By("hwnd", _ieHwnd));
这给出了错误:
Class Cleanup method Class1.MyClassCleanup failed. Error Message: WatiN.Core.Exceptions.BrowserNotFoundException: Could not find an IE window matching constraint: Attribute 'hwnd' equals '1576084'. Search expired after '30' seconds.. Stack Trace: at WatiN.Core.Native.InternetExplorer.AttachToIeHelper.Find(Constraint findBy, Int32 timeout, Boolean waitForComplete)
我相信我一定会错过一些明显的东西,有没有人对此有任何想法? 感谢
为了完整起见,静态辅助看起来是这样的:
public class StaticBrowser
{
private IE _instance;
private int _ieThread;
private string _ieHwnd;
public IE Instance
{
get
{
var currentThreadId = GetCurrentThreadId();
if (currentThreadId != _ieThread)
{
_instance = IE.AttachTo<IE>(Find.By("hwnd", _ieHwnd));
_ieThread = currentThreadId;
}
return _instance;
}
set
{
_instance = value;
_ieHwnd = _instance.hWnd.ToString();
_ieThread = GetCurrentThreadId();
}
}
private int GetCurrentThreadId()
{
return Thread.CurrentThread.GetHashCode();
}
}
而且清理代码如下所示:
private static StaticBrowser _staticBrowser;
[ClassCleanup]
public static void MyClassCleanup()
{
_staticBrowser.Instance.Close();
_staticBrowser = null;
}
我遇到了同样的问题,但我既没有使用MSTest也没有使用MbUnit。 您的环境中是否有其他可能解决此问题的更改? – 2010-12-01 01:23:06
我认为这取决于测试执行线程的方式,它描述了各种设置; http://watin.sourceforge.net/apartmentstateinfo.html 我的方式是通过FixtureSetUp导航到页面执行操作等,然后关闭FixtureTearDown中的浏览器。 WatiN在其他配置上表现不佳。 – 2011-01-07 14:07:31