2
votes

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?

2

2 Answers

1
votes

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

0
votes

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>