Watin 单元测试与 Nunit 计时问题

发布于 2024-08-12 17:48:22 字数 1225 浏览 8 评论 0原文

您好,我正在使用 WatiN(版本 2.0.10.928)和 NUnit(2.5.2.9222) 如果我有类似的东西 <代码>

  [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?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人间不值得 2024-08-19 17:48:22

恐怕您使用的测试框架没有什么区别——这是任何屏幕抓取测试框架的“陷阱”之一,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.

别忘他 2024-08-19 17:48:22

我的测试也遇到了同样的问题;不幸的是,您似乎不能假设 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 the Click() method will function correctly. Even explicitly calling WaitForComplete() 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.

温暖的光 2024-08-19 17:48:22

尝试使用

    [Test]  
    public void WebPageTest()  
    {  
        string url = "www.google.com";  
        IE ie = new IE(url);  
        ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin");  
        var btnG = ie.Button(Find.ByName("btnG"));  
        btnG.ClickNoWait();  
        ie.WaitForComplete(400);  
        var elementWatin = ie.Element(Find.ByText("WatiN"));  
        elementWatin.ClickNoWait();  
        ie.WaitForComplete(400);  
        Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN"));  
        ie.Close();  
    }

谢谢
甘地·拉詹

Try using

    [Test]  
    public void WebPageTest()  
    {  
        string url = "www.google.com";  
        IE ie = new IE(url);  
        ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin");  
        var btnG = ie.Button(Find.ByName("btnG"));  
        btnG.ClickNoWait();  
        ie.WaitForComplete(400);  
        var elementWatin = ie.Element(Find.ByText("WatiN"));  
        elementWatin.ClickNoWait();  
        ie.WaitForComplete(400);  
        Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN"));  
        ie.Close();  
    }

Thanks
Gandhi Rajan

Hello爱情风 2024-08-19 17:48:22

我已经使用了 ie.WaitForComplete() 但它仍然强制等待,有时会超时,所以我使用

  Settings.AttachToBrowserTimeOut = 200;
  Settings.WaitForCompleteTimeOut = 200;

这对我有用。

I have used ie.WaitForComplete() but it still does enforce waiting, and sometimes it times out, so I use

  Settings.AttachToBrowserTimeOut = 200;
  Settings.WaitForCompleteTimeOut = 200;

This worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文