【问题标题】:Setting apartment state for using WatIn with MSTest设置公寓状态以将 WatIn 与 MSTest 结合使用
【发布时间】:2010-12-13 20:00:27
【问题描述】:

我收到以下错误:

CurrentThread 需要将其 ApartmentState 设置为 ApartmentState.STA 才能使 Internet Explorer 自动化。

使用以下代码:

    [TestClass]
    public class UnitTest1
    {

    [AssemblyInitialize]
    public static void AssemblySetup(TestContext context)
    {

    }

    [TestMethod]
    [HostType("ASP.NET")]
    [AspNetDevelopmentServerHost("C:\\SomePath", "/")]
    [UrlToTest("http://localhost/HomeView.aspx")]
    public void TestMethod1()
    {
        using(IE ie = new IE("http://localhost/HomeView.aspx",true))
        {
            ie.TextField(Find.ById("MainContent_txtDLNumber")).TypeText("a235801945550");
        }
    }
}

是否有不同的方法将 WatIn 与 MsTest 结合使用?

【问题讨论】:

    标签: visual-studio-2010 nunit mstest watin webtest


    【解决方案1】:

    你可能需要相应地调整你的配置,下面应该会给你一个线索

    <configuration>
      <configSections>
        <sectionGroup name="NUnit">
          <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
      </configSections>
    
      <NUnit>
        <TestRunner>
          <!-- Valid values are STA,MTA. Others ignored. -->
          <add key="ApartmentState" value="STA" />
        </TestRunner>
      </NUnit>
    
    
    </configuration>
    

    【讨论】:

    • 这是正确的。实际上,我使用的是 resharper 测试运行器,它需要与 Nunit 测试运行器相同的配置设置。
    • @japrram:问题标签是否应该更新为列出 nunit 而不是 mstest?
    【解决方案2】:

    考虑更新您的代码以使用具有RequiresSTA 属性的 NUnit 2.5。

    【讨论】:

      【解决方案3】:

      试试这个:

      [STAThread]
      static void Main(string[] args)
      {
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-08
        • 2021-10-02
        • 1970-01-01
        • 1970-01-01
        • 2018-11-08
        • 2013-04-10
        • 1970-01-01
        相关资源
        最近更新 更多