1

I am getting the following error in:

The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

With the following code:

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

Is there a different approach for using WatIn with MsTest?

dove
  • 20,469
  • 14
  • 82
  • 108
jparram
  • 804
  • 8
  • 24

3 Answers3

0

Try this instead:

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

You will probably need to adjust your config accordingly, below should give you a clue

<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>
dove
  • 20,469
  • 14
  • 82
  • 108
  • This is correct. Actually, I was using the resharper test runner which required the same config settings as the Nunit test runner. – jparram Dec 29 '10 at 17:31
  • 1
    @japrram: should the question tag be updated to list nunit instead of mstest? – GregC Apr 28 '11 at 05:36
0

Consider updating your code to use NUnit 2.5 with RequiresSTA attribute.

GregC
  • 7,737
  • 2
  • 53
  • 67