【发布时间】:2010-11-19 17:02:19
【问题描述】:
我正在尝试使用 WatiN 进行 UI 测试,我可以让测试正常工作,但之后我无法让 IE 关闭。
我正在尝试在我的班级清理代码中关闭 IE,使用 WatiN 的示例 IEStaticInstanceHelper technique。
问题似乎是附加到IE线程,超时:
_instance = IE.AttachTo<IE>(Find.By("hwnd", _ieHwnd));
(_ieHwnd 是 IE 首次启动时存储的 IE 句柄。)
这给出了错误:
类清理方法 Class1.MyClassCleanup 失败。错误 信息: WatiN.Core.Exceptions.BrowserNotFoundException: 找不到匹配的 IE 窗口 约束:属性“hwnd”等于 '1576084'。搜索在“30”后过期 秒..堆栈跟踪:在 WatiN.Core.Native.InternetExplorer.AttachToIeHelper.Find(约束 findBy,Int32 超时,布尔值 等待完成)
我确定我一定遗漏了一些明显的东西,有人对此有任何想法吗? 谢谢
为了完整起见,静态助手看起来像这样:
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;
}
【问题讨论】:
标签: testing watin ui-testing