If you are trying to use WatiN
for web application testing through Internet Explorer, ensure to complete the right configurations first.
NUnit
doesn't run tests in a thread using the STA apartment state
; it uses multithreaded apartment (MTA)
, but this isn't a big problem, you can attach config file to the NUnit
test project and specify the apartment state mode that you want this way:
<?xml version="1.0" encoding="utf-8" ?>
<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>
Article Reference:
WatiN, Internet Explorer and Thread.Apartmentstate
This article explains the why and how about setting the ApartmentState of a Thread to single treaded apartment (STA). This is required when running your test with Internet Explorer. It also shows you how to do this when using WatiN with NUnit, MBUnit, MSTest, TestDriven.Net, Fitnesse or SharpDevelop.