Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance WatiN Dispose()真的很慢_Performance_Internet Explorer 8_Windows Xp_Watin_Slowdown - Fatal编程技术网

Performance WatiN Dispose()真的很慢

Performance WatiN Dispose()真的很慢,performance,internet-explorer-8,windows-xp,watin,slowdown,Performance,Internet Explorer 8,Windows Xp,Watin,Slowdown,当我处理Internet Explorer对象时,我的WatiN测试突然变得非常慢 这是我的设置 * Windows 7 (Evaluation Build 7100) * Internet Explorer 8 (Version 8.0.7100.0) * WatiN (Version 2.0.10.928) 这很奇怪,因为大约一周前,测试工作还不错。我想这是微软最新的更新 有什么想法吗?我在IE9上也遇到了同样的间歇性问题。我和我的同事都没有同样的问题。我们刚刚意识到,我的默认浏览器是IE

当我处理Internet Explorer对象时,我的WatiN测试突然变得非常慢

这是我的设置

* Windows 7 (Evaluation Build 7100)
* Internet Explorer 8 (Version 8.0.7100.0)
* WatiN (Version 2.0.10.928)
这很奇怪,因为大约一周前,测试工作还不错。我想这是微软最新的更新


有什么想法吗?

我在IE9上也遇到了同样的间歇性问题。我和我的同事都没有同样的问题。我们刚刚意识到,我的默认浏览器是IE,我倾向于打开它并运行几个选项卡

当我的WatIn测试运行时,我一直在使用桌面上没有打开的IE,自从我采用这种做法以来,我就没有遇到过这个问题

可能是巧合,也可能是答案

我在IE关闭缓慢(或从不关闭)时遇到问题,但在执行以下操作后,我没有遇到任何问题:
  • 而不是Mikecito所描述的模式 链接,我使用BrowserStaticInstanceHelper的一个版本,如 杰伦·范·梅宁,瓦廷英雄。它提供了一种在和中归零的方法 附加到特定的浏览器窗口
  • 使用此策略可以为多个测试方法和多个测试类只启动一个IE。当所有测试完成后,IE将在1或2秒内关闭
  • 最后一期: 因为我有多个TestMethods和TestClass,所以我想将IE.Close()放在AssemblyCleanup()方法中。由于MSTest线程问题,我不得不调用close(),如下所示:

    [AssemblyCleanup()]
    public static void CleanupAllTests()
    {
        var thread = new Thread(() =>
        {
            IE.Close();
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();
    }
    
    *同样,此代码段中的IE引用了一个属性,该属性将使用上面链接中的策略检查并附加到我的IE实例。如果没有我链接到的其他模式,这个片段可能无法解决您的问题


    在此之前,IE有时需要30多秒才能关闭,现在我可以在测试运行时随意打开和关闭其他IE窗口,并且浏览器始终可靠关闭。

    您需要做的是将测试运行的线程设置为STA模式,IE将快速关闭

     [CodedUITest]
     public class DoSomeAutomatedTesting
     {
         public DoSomeAutomatedTesting()
         {
             // Hey! Hey! Hey! We can't do no MTA!
             Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
         }
    
         [TestMethod]
         public void MyTestMethod()
         {
             using(var ie = new IE())
             {
                 ie.AutoClose = true;
                 ie.GoTo("http://www.google.com");
             }     
        }
    }
    
    对于那些不是做过COM编程的老混蛋的人来说,这描述了一个STA。简而言之,STA是COM使用的一种老派技术,它在可怕的、新型的先发制人的多线程世界中保留了Windows 95天遗留下来的现有的、经过测试的、可工作的单线程代码的生存能力

    现在,CLR存在于COM所称的MTA中。对于我们这些不生活在1998年的人来说,你可以把MTA想象成真实的世界,在那里,事情按照它们应该的方式运作


    当超级恐怖MTA中的某个线程想要访问STA中的某些内容时,MTA线程会被告知坐在工作台上等待轮到它的时间,如果STA当前正由MTA中的其他线程访问。这基本上意味着,有时,当天气不好时,你可以得到这些wierd-o滞后。

    我知道这是老问题,但其他人是否也遇到类似问题?你能发布一个你调用的Watin函数的代表性示例以及它们的频率吗?这是唯一解决我缓慢关闭问题的方法。
     [CodedUITest]
     public class DoSomeAutomatedTesting
     {
         public DoSomeAutomatedTesting()
         {
             // Hey! Hey! Hey! We can't do no MTA!
             Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
         }
    
         [TestMethod]
         public void MyTestMethod()
         {
             using(var ie = new IE())
             {
                 ie.AutoClose = true;
                 ie.GoTo("http://www.google.com");
             }     
        }
    }