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.

Publicerat av Ola

WordPress, UX och e-handels frilans. Driver varumärket Sten. Jobbar som lärare inom webb, media och IT på NTI Gymnasiet.

5 svar på ”Write to TinyMCE in a WatiN integration test”

  1. Hi, when I run your code in my Watin test I get the error message ’tinymce is undefined’. The tiny_mce.js is included in the page but it seems not to work. Any idea?

  2. Hi,

    Do you have TinyMCE running on the page you are trying to test via WatiN?

    Also make sure you use the right ID (mine is tinyTextAreaId). It should be the ID to the html text area that TinyMCE has replaced.

    Good luck!

  3. In my case, I’m not able to use the Eval() medhod, since it’s not static. I cannot generate a Document instance either. In detail, I’m using the class Watin.Core.Document. Maybe I’m missing a reference, namespace or something.
    Do you have any idea? Thanks

  4. Absolutely Amazing! – Thank you so much. I was spending hours trying to figure out how to do that. And all it takes are 2 lines of code!

Kommentarer inaktiverade.