Issues with tests that reference WatiN (VS 2005 Test Runner)

I am using Watin to create web tests in vs 2005. I believe my issue is with the actual execution of the build runner. Here is an example test with WatiN:


public void WatiNTest()
{
IE ie = new IE("www.google.com");

List pages = new List(); foreach (Link link in ie.Links) { pages.Add(link.Url); Console.WriteLine(link.Url); } ie.Close(); Assert.AreEqual(27, pages.Count, "The number of links has changed."); } I get the fllowing error when the test is run by TeamCity: System.Threading.ThreadStateException : The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer. at WatiN.Core.IE.CheckThreadApartmentStateIsSTA() at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, LogonDialogHandler logonDialogHandler, Boolean createInNewProcess) at WatiN.Core.IE..ctor(String url) at ScrapeCompare.UnitTest1.WatiNTest() in c:\Program Files\TeamCity\buildAgent\work\741796eb2b4d6e6a\ScrapeCompare\UnitTest1.cs:line 47 Is it possible to setup some kind of environment variable or property on the build config? FYI: >>]]> http://watin.sourceforge.net/apartmentstateinfo.html#consoleOrWinForm

Thanks,
Roger

Edited by: Roger Guess on Apr 11, 2008 5:03 PM

2 comments

Resolved...

I looked at the detail log of the build and realized it was actually running NUnit (I think). So I used the instructions from this:

http://watin.sourceforge.net/apartmentstateinfo.html#nunit

I added a config file (assemblyname.dll.config) to my test project. Then updated it's properties (content and copy always). And now it's working.

]]>

0

I am still having problems getting my testing to run on my home computer. I am using Microsoft Visual C# 2008 and have added the config settings stated and have the properties adjusted as listed as well. When I run these tests at work using Visual Studio 2005, there is not any problems, so I am guessing there is something with the 2008 version that I need to adjust. Any ideas?

Many thanks for any assistance.

0

Please sign in to leave a comment.