Write to TinyMCE in a WatiN integration test

Last week I worked on some integration tests in Selenium. Today I’m redoing the same test in WatiN to get a feel for both tools.

Since the application uses TinyMCE for most of it’s text inputs I had to find a way to write to it within the tests. With Selenium Nick Bartlett had a solution. For WatiN I used the Eval method and executed the setContent JavaScript method in the TinyMCE API.

var js = "tinyMCE.get('tinyTextAreaId').setContent('some html');";
var s = Document.Eval(js);

This would work just as good with Selenium and it has one advantage over setting the text areas. It executes the eventual cleanup rules in TinyMCE before it sets the text.

Running WatiN tests in SharpDevelop

I tried to run my WatiN tests in the test runner in SharpDevelop and got stuck on the following error:

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

If you are running your tests with MBUnit you can add the following to your TestFixture:

[TestFixture(ApartmentState = ApartmentState.STA)]

But I couldn’t find any similar for NUnit. Instead I changed how SharpDevelop launches it’s tests. Click; Tools / Options / Tools / Unit Tests and deselect Run tests on separate thread. Run the tests again.

And I got the following error:

System.InvalidOperationException : Process has exited, so the requested information is not available.

I tried to disable Protected Mode in Internet Explorer and the tests ran fine.

How to dissable Protected Mode in IE
How to disable Protected Mode in IE