1

我收到以下错误:

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 结合使用是否有不同的方法?

4

3 回答 3

0

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

<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>
于 2010-12-24T13:07:20.703 回答
0

试试这个:

[STAThread]
static void Main(string[] args)
{
}
于 2013-04-28T22:09:33.123 回答
0

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

于 2011-04-28T05:36:15.143 回答