WatiN Dispose() 真的很慢

发布于 2024-08-01 15:21:45 字数 274 浏览 5 评论 0原文

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

这是我的设置...

* Windows 7 (Evaluation Build 7100)
* Internet Explorer 8 (Version 8.0.7100.0)
* WatiN (Version 2.0.10.928)

这很奇怪,因为大约一周前测试运行良好。 我认为这是最新的微软更新或其他什么。

有任何想法吗?

My WatiN tests have suddenly gotten REALLY slow when I dispose the Internet Explorer object.

Here's my setup...

* Windows 7 (Evaluation Build 7100)
* Internet Explorer 8 (Version 8.0.7100.0)
* WatiN (Version 2.0.10.928)

This is strange because the tests were working fine a week or so ago. I think it's the latest MS Updates or something.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

多孤肩上扛 2024-08-08 15:21:45

我遇到了 IE 缓慢关闭(或从不关闭)的问题,但在执行以下操作后,我遇到了零问题:

My setup:
*IE 9
*Windows 7
*Watin 2.1
*Visual Studio 10 SP1, using Microsoft.VisualStudio.TestTools.UnitTesting
  1. 而不是像 Mikecito 中描述的那样的模式
    链接,我使用由以下描述的 BrowserStaticInstanceHelper 版本
    Jeroen van Menen,Watin 英雄,此处。 它提供了一种归零和
    附加到特定的浏览器窗口。
  2. 使用这一策略的好处是,只需为多种测试方法和多个测试类启动一个 IE。 并且,当所有测试完成后,IE 将在 1 或 2 秒内关闭。

最后一个问题:

由于我有多个 TestMethods 和 TestClasses,我想将 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 窗口,并且浏览器始终可靠地关闭。

I was having issues with IE closing slowly (or never), but after doing the following I've had zero issues:

My setup:
*IE 9
*Windows 7
*Watin 2.1
*Visual Studio 10 SP1, using Microsoft.VisualStudio.TestTools.UnitTesting
  1. Rather than a pattern like those described in Mikecito's
    links, I use a version of the BrowserStaticInstanceHelper described by
    Jeroen van Menen, Watin hero, here. It provides a way to zero in and
    attach to a specific browser window.
  2. Using this strategy has the bonus of only starting up one IE for multiple test methods and multiple test classes. AND, when all tests finish, IE closes within 1 or 2 seconds.

One last issue:

Since I have multiple TestMethods and TestClasses, I wanted to put IE.Close() in an AssemblyCleanup() method. Due to MSTest threading issues, I then had to call close() like this:

[AssemblyCleanup()]
public static void CleanupAllTests()
{
    var thread = new Thread(() =>
    {
        IE.Close();
    });
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
}

*Again, IE in this snippet refers to a property that will check for and attach to my IE instance using the strategy from the link above. This snippet probably won't solve your problems without the rest of the pattern that I linked to.

Before this setup IE would sometimes take 30+ seconds to close, now I can open and close other IE windows all I want while the tests are running, and the browser always closes reliably.

很酷不放纵 2024-08-08 15:21:45

您需要做的是将运行测试的线程设置为 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 http://msdn.microsoft.com/en-us/library/windows/desktop/ms680112(v=vs.85).aspx。 简而言之,STA 是 COM 使用的一种老式技术,用于保留 Windows 95 时代遗留下来的现有的、经过测试的、可工作的单线程代码在可怕的、新奇的抢占式多线程世界中的可行性。

现在,CLR 位于 COM 所称的 MTA 中。 对于我们这些没有生活在 1998 年的人来说,您可以将 MTA 视为现实世界,那里的一切都按其应有的方式运行。 http://msdn.microsoft。 com/en-us/library/windows/desktop/ms693421(v=vs.85).aspx

当超级可怕的 MTA 中的某个线程想要访问 STA 中的某些内容时,MTA 线程被告知坐下如果 STA 当前正由与 MTA 不同的线程访问,则在工作台上等待轮到它。 这基本上意味着,有时,当天气不合适时,您可能会出现这些奇怪的滞后现象。

What you need to do is set the thread the test is running on into STA mode, and IE will close quickly.

 [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");
         }     
    }
}

For those of you who aren't old farts who have done COM programming, this describes an STA http://msdn.microsoft.com/en-us/library/windows/desktop/ms680112(v=vs.85).aspx. Short story, STA is an old-school technique used by COM to preserve the viability of existing, tested, working, single-threaded code left over from the Windows 95 days in the scary, new-fangled world of preemptive multithreading.

Now, the CLR lives in what the COM calls the MTA. For those of us that don't live in 1998, you can think of the MTA as the real world, where things work the way they should. http://msdn.microsoft.com/en-us/library/windows/desktop/ms693421(v=vs.85).aspx

When some thread in the super-scary MTA wants to access something in an STA, the MTA thread is told to sit on the bench and wait its turn if the STA is currently being accessed by a different thread from the MTA. This basically means that sometimes, when the weather isn't right, you can get these wierd-o lags.

纵情客 2024-08-08 15:21:45

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

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

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

I've been having the same, intermittent problem with IE9. My colleagues either side of me do not have the same issues. We have just realised that my default browser is IE and I tend to have it open with several tabs running.

I've been working with no IE open on the desktop while my WatIn tests run and I haven't had the problem since I adopted this practice.

Possibly coincidence, or possibly the answer?!

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