Watin 单元测试与 Nunit 计时问题
您好,我正在使用 WatiN(版本 2.0.10.928)和 NUnit(2.5.2.9222) 如果我有类似的东西 <代码>
Then usually this will work and the test will pass but sometimes when I hit the assert it seems that Watin hasn't finished loading the page and is still on the previous page. I have this problem using the IE.Text or the IE.Url properties. I tried using WaitForComplete() (even though that shouldn't be neccessary) but still sometimes have the same problem.[Test] public void WebPageTest() { string url = "www.google.com"; IE ie = new IE(url);
ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin"); ie.Button(Find.ByName("btnG")).Click();
ie.Element(Find.ByText("WatiN")).Click();// ie.WaitForComplete(); Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN")); ie.Close(); }
<代码>
Has Anybody had this problem with WatiN before? Has anybody succesufully managed to use WatiN with NUnit like this? Or Maybe it would work better with a different unit testing framework like MBUnit? Has anyone had better luck with MBunit?
Hi i am using WatiN (version 2.0.10.928) with NUnit (2.5.2.9222)
if I have something like
[Test] public void WebPageTest() { string url = "www.google.com"; IE ie = new IE(url);
ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin"); ie.Button(Find.ByName("btnG")).Click();
ie.Element(Find.ByText("WatiN")).Click();// ie.WaitForComplete(); Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN")); ie.Close(); }
Then usually this will work and the test will pass but sometimes when I hit the assert it seems that Watin hasn't finished loading the page and is still on the previous page. I have this problem using the IE.Text or the IE.Url properties. I tried using WaitForComplete() (even though that shouldn't be neccessary) but still sometimes have the same problem.
Has Anybody had this problem with WatiN before?
Has anybody succesufully managed to use WatiN with NUnit like this? Or Maybe it would work better with a different unit testing framework like MBUnit? Has anyone had better luck with MBunit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
恐怕您使用的测试框架没有什么区别——这是任何屏幕抓取测试框架的“陷阱”之一,WaTin 也不例外。
恐怕
WaitForComplete()
调用绝对是必要的。我的一些同事报告说,IE 的版本可能会有所不同;特别是 IE6 存在一些可能导致问题的内部计时问题。 IE8 似乎要好一些。
The test framework you use will make no difference, I'm afraid -- this is one of the "gotchas" of any screen-scraping test framework, and WaTin is no different.
The
WaitForComplete()
call is definitely necessary, I'm afraid.Some of my colleagues have reported that the version of IE can make a difference; IE6 in particular has some internal timing issues that can cause problems. IE8 appears to be quite a bit better.
我的测试也遇到了同样的问题;不幸的是,您似乎不能假设
Click()
方法中固有的WaitForComplete()
能够正常运行。即使事后显式调用WaitForComplete()
也并不总是有效。作为最后的手段,我们使用 System.Threading.Thread.Sleep(int timeout_in_milliseconds) 来强制浏览器给予页面加载时间。这并不是一种完全万无一失的方法,但它已经消除了大约 90% 的此类错误。对于超时,我们使用了 500 到 2000 毫秒之间的任何值,具体取决于加载所需的时间以及我们希望测试运行的速度。
I've had the same problem with my tests; unfortunately it doesn't seem as though you can assume that the
WaitForComplete()
that's supposed to be inherent in theClick()
method will function correctly. Even explicitly callingWaitForComplete()
afterward hasn't always worked.As a last resort we have used
System.Threading.Thread.Sleep(int timeout_in_milliseconds)
to force the browser to give the page time to load. This isn't a completely bulletproof means of doing it, but it has eliminated about 90% of these sorts of errors. For the timeout we have used anything from 500 to 2000 milliseconds, depending on how long it takes to load and how quickly we want the test to run.尝试使用
谢谢
甘地·拉詹
Try using
Thanks
Gandhi Rajan
我已经使用了 ie.WaitForComplete() 但它仍然强制等待,有时会超时,所以我使用
这对我有用。
I have used ie.WaitForComplete() but it still does enforce waiting, and sometimes it times out, so I use
This worked for me.