Selenium, PHPUnit, and TinyMCE
Nearly two years ago, I wrote a quick note on how to switch iframes in PHPUnit/Selenium to populate an xhEditor text area.
Because we’re seeing a lot of formatted text cut/pasted from Microsoft Word, we needed to replace xhEditor with a WYSIWYG that does a better job of stripping out all of the horrible cruft that the Word formatting causes. TinyMCE seems to do a decent job (given the impossible nature of the requirements), but my test code no longer works.
Here’s how I got it working again. I added a function to my base WebTestCase:
protected function typeInTinyMCE($text,$field) { $this->getEval("selenium.browserbot.getUserWindow()."+ "tinyMCE.get('".$field."').setContent('".addslashes($text)."');"); }
Then, in any arbitrary functional test, I can type stuff into my TinyMCE field:
public function testWhatever() { $this->login(); $this->click("link=WYSIWYG Page"); $this->waitForPageToLoad("30000"); $this->typeInTinyMCE('Hey, I can put stuff into my WYSIWYG field!','field_id'); ... }
Leave a Reply