Pregunta

Estoy recibiendo el siguiente error en:

El CurrentThread necesita tener que ApartmentState del conjunto de ApartmentState.STA ser capaz de automatizar Internet Explorer.

Con el siguiente código:

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

¿Hay un enfoque diferente para el uso de Watin con MSTEST?

¿Fue útil?

Solución

Es probable que tenga que ajustar su configuración en consecuencia, a continuación deben darle una pista

<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>

Otros consejos

Considere actualizar su código para utilizar NUnit 2.5 con RequiresSTA atributo.

Pruebe esto en su lugar:

[STAThread]
static void Main(string[] args)
{
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top