fogbound.net




Wed, 13 Feb 2013

PHPUnit/Selenium and iframes

— SjG @ 10:20 am

I ran into an interesting issue with a functional test, and wasn’t able to Google a specific solution out there. So here’s my solution.

The Problem:
When testing a web form that contains a Javascript “wysiwyg” editor (in this case xhEditor, since it’s a site built on Yii, and there’s a great extension), the Selenium IDE was not logging anything typed into that field. When I tried using the field ID, the data was also silently vanishing.

The Explanation:
xhEditor converts the TextArea into an iFrame, and captures keystrokes to populate the HTML body of the dependent frame. The Selenium plugin for Firefox doesn’t grok this, and the data goes missing.

The Solution:
Manually switch frames in your PHPUnit/Selenium code.

$this->selectFrame("//*[@id='xhEdt0_iframe']"); // switch to the iframe
$this->type("//body","This text shows up in the xhEdit WYSIWYG!"); // type into the body
$this->selectFrame("relative=top"); // switch back to the surrounding frame


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.