WatiN 间歇性故障 [英] WatiN Intermittent Failures

查看:44
本文介绍了WatiN 间歇性故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队有一堆由我们的 TeamCity 服务器自动运行的 WatiN 测试套件.我们最近将所有构建代理切换到 64 位,我还将我们的 WatiN 测试切换为在 x64 模式下使用 NUnit.由于对 IE 浏览器的互操作调用失败或其他原因,Watin 总是给我们带来不常见的测试失败,但这些总是非常罕见.由于将所有内容都切换到 64 位,几乎我们任何测试套件的每次运行都会失败,并出现以下异常:

My team has a bunch of WatiN test suites which run automatically by our TeamCity server. We recently switched all of our build agents to 64 bit and I also switched our WatiN tests to use NUnit in x64 mode. Watin has always given us infrequent test failures because of failed Interop calls to the IE browser or for other reasons but these have always been quite rare. Since switching everything to 64 bit, almost every run of any of our test suites fails with the following Exception:

Test(s) failed. System.InvalidCastException : Specified cast is not valid.
    at SHDocVw.IWebBrowser2.get_HWND()
    at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd()
    at WatiN.Core.DomContainer.StartDialogWatcher()
    at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
    ...

我发现了一个相关问题,其中一位 WatiN 用户看到了同样的异常,但这是因为她正在尝试多线程.我们没有做任何这样的事情,事实上我们正在使用 WatiN 文档建议的正确线程状态单元.我确实在问题中注意到有人评论说这可能是因为 x86 与 x64 模式.

I found a related question where a WatiN user is seeing the same exception but it is because she is attempting multi-threading. We are not doing any such thing, infact we are using the correct thread state apartment as suggested by the WatiN documentation. I did notice in the question though that someone had commented saying it might be because x86 vs. x64 mode.

如何避免此错误导致我的测试经常失败?

How can I avoid this error causing my tests to frequently fail?

如果只是切换回 32 位模式的问题,我可以处理,但我想确定没有更好的解决方案.谢谢.

If it is simply a matter of switching back to 32 bit mode, I can handle that but I wanted to know for sure that there is no better solution. Thanks.

更新:
在将作业保留为使用 64 位 NUnit 运行器进行大约 5 次以上的测试套件运行后,除了一次出现相同的错误外,它们每次都失败.我们将它们切换回 32 位,此后已成功运行 10 多次.我想目前的临时修复是使用 32 位 NUnit 运行程序,尽管我仍在寻找发生这种情况的原因或允许我们切换回 x64 的解决方案.

UPDATE:
After leaving the jobs as using 64 bit NUnit runner for about 5+ runs of the test suites, they failed every time except once with this same error. We switched them back to 32 bit and have had 10+ successful runs since. I guess the temporary fix for now is use a 32 bit NUnit runner although I am still looking for a reason this happens or a solution that would allows us to switch back to x64.

推荐答案

我在 x64 上使用 Watin,这给我带来了一些麻烦.我最近查看了 Watin 的源代码,似乎 PInvoke 调用存在缺陷(仅在 32b 系统上正确工作).如果您执行某些方法,它们会覆盖内存的某些部分(因为 32b 是为 64b 结果保留的),从而产生奇怪的错误.

I am using Watin on x64 and it caused me some troubles. I recently reviewed the source code of Watin and it seems the PInvoke calls are flawed (working only on 32b system correctly). If you execute certain methods they overwrite some parts of memory (as 32b is reserved for 64b result) thus making strange errors.

这只是一个例子:WatiN-2.1.0.1196/source/src/Core/Native/Windows/Win32.cs

This is just an example one: WatiN-2.1.0.1196/source/src/Core/Native/Windows/Win32.cs

public static extern Int32 SendMessageTimeout(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam, Int32 fuFlags, Int32 uTimeout, ref Int32 lpdwResult);

VS 正确

public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout, out IntPtr lResult);

要查看完整更改,请查看 http://pastebin.com/KaVpM6wT当然,它需要重建 Watin.Core dll 并且没有保修.

For full change check http://pastebin.com/KaVpM6wT It needs a rebuild of the Watin.Core dll of course and comes with no warranty.

这篇关于WatiN 间歇性故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆