views:

619

answers:

2

I've gotten a simple WatiN web test running on my dev environment and am trying to get it working on the TFS build server. WatiN is firing an exception:

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

The test runner, VSTestHost supposedly uses STA threading by default. I've also tried explicitly forcing it to STA via the .testrunconfig file. Still WatiN is unhappy. I'm using Visual Studio/TFS 2008 on Windows Server 2008.

Has anyone else hit this problem and found a solution?

A: 

Editing the testrunconfig as you suggest should be the solution. What syntax did you try? as far as I can recall for 2008 it's

 <ExecutionThread apartmentState="1" />

and for 2005 it's

<apartmentState type="System.Threading.ApartmentState">
  <value__ type="System.Int32">1</value__>
</apartmentState>
Bruce McLeod
I used, <ExecutionThread apartmentState="STA" /> which should be valid, but redundant.See http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/a7b31008-457a-49bb-baa0-815cec38a8ed
Craig Fisher
The ="1" syntax is not valid according to this blog post:http://blogs.msdn.com/irenak/archive/2008/02/22/sysk-365-how-to-get-your-unit-tests-test-project-in-visual-studio-2008-a-k-a-mstest-run-multithreaded.aspx
Craig Fisher
A: 

You might want to check/use [STAThread] attribute for your WatiN test methods

Shady M. Najib