代码之家  ›  专栏  ›  技术社区  ›  Pavlo Neiman

MSTEST中的watin-ClassCleanup失败

  •  5
  • Pavlo Neiman  · 技术社区  · 14 年前

    螺纹内螺纹 WatiN in Visual Studio 2008 - second test method fails IEStaticInstanceHelper有一个很好的解决方案(原始答案 Reusing an IE instance in VS test , sources ,但当类清理触发它时 失败 在附件上。因此,iExplorar仍在运行。

    有什么问题?

    当然,可以这样终止这个过程:

    // Id of IEXPLORAR
    _ie.ProcessID
    
    Process.GetProcessById(_processId).Kill();
    this._ie = null;
    

    但我不太喜欢这样…

    有什么想法吗?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Adnan    13 年前

    它失败是因为MSTEST在多线程单元中执行类清理,甚至认为它在STA中运行单个测试。Waitn连接到IE的方式包括查找不安全线程且不暴露于MTA的COM对象。

    谢谢你的进程终止解决方案,现在也使用它,尽管我正在使用 CloseMainWindow() 而不是 Kill()

        2
  •  0
  •   stephen    14 年前

    可以将通配符与watin的attachto方法一起使用来获取现有的浏览器实例。这将允许您在后续测试中重新使用浏览器实例,或者关闭浏览器(如果您对此感兴趣的话)。例如:

    // find first browser matching our wildcard
    IE found = Browser.AttachTo<IE>(Find.ByTitle(new Regex(".*")));
    
    // then close just that one
    found.Close();
    
    // or close all running IE instances at once
    // found.ForceClose();
    

    可以使用具有相同find约束的exists方法确定是否有要附加到的IE实例。例如:

    Constraint browserWildcard = Find.ByTitle(new new Regex(".*"));
    if(IE.Exists<IE>(browserWildcard))
    {
      // ...
    }