Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatiN in MSTest - ClassCleanup fail

Tags:

c#

mstest

watin

In thread WatiN in Visual Studio 2008 - second test method fails there is a good solution with IEStaticInstanceHelper (original answer Reusing an IE instance in VS test, sources), but when ClassCleanup fires it fails on AttachToIE. As result IEXPLORAR remain running.

What is the problem?

Of course it is possible to just kill the process like this:

// Id of IEXPLORAR
_ie.ProcessID

Process.GetProcessById(_processId).Kill();
this._ie = null;

But I don't really like this way...

Any ideas?

like image 299
Pavlo Neiman Avatar asked Nov 06 '22 15:11

Pavlo Neiman


1 Answers

It fails because MSTest does the class cleanup in a multi-threaded apartment, even thought it runs individual tests in an STA. The way WaitN attaches to IE involves looking up COM objects that aren't thread safe, and aren't exposed to MTA.

Thanks for the process kill workaround, using that too now, although I'm using CloseMainWindow() rather than Kill()

like image 149
Laurence Avatar answered Nov 15 '22 06:11

Laurence