Using Selenium to Test ColdFusion Richtext

In the course of trying to get ready to release the code for Yet Another ColdFusion CMS, or Yacc, I was trying to test working with the CMS. In order to do that, I needed to get Selenium to work with it. It worked fine until I tried to edit content. I’m using cftextarea richtext=true to provide CMS editing capabilities. However, when I went to record the test in Selenium, it couldn’t handle working with FCKeditor which provides the richtext capabilities for ColdFusion. After a few hours of trial and error, I was able to test them.

Here’s how you do it:

First you have to do it via Selenium-RC, the Selenium Firefox IDE doesn’t seem to be able to do it. You can launch pretty easily via ANT:

<!–
Prerequsites
for
selenium–>    

<taskdef
resource=“selenium-ant.properties”>

    <classpath>

        <pathelement
location=“${selenium.jar}”/>

    </classpath>

</taskdef>

<target
name=“template.test.selenium”>

    <echo
message=“Running Selenium Tests.”
/>

            

    <selenese

        suite=“${template.test.selenium.suite}”

        browser=“*pifirefox”

        results=“${log.dir}templateuitestresults.html”

        haltOnFailure=“true”

        timeoutInSeconds=“240”

        startURL=“${host.url}”

     />

                

</target>

Where:

${selenium.jar}

The path of the selenium-server.jar file

${template.test.selenium.suite}

The path to the selenium test suite.

${log.dir}

The path to a space where you store logs

${host.url}

The base url of the testing webserver

pifirefox

This is the proxy Injection version of Firefox launcher

 

Now you’re launching your Selenium tests automatically in ANT, but you have to write your tests to actually interact with the FCKEditor. By default Selenium runs its tests as soon as the page loads. But in order to test the FCKEditor, you have to wait for it to exist. Here’s the Selenese to do that:

<tr>

    <td>waitForCondition</td>

    <td>typeof(window.ColdFusion) != ‘undefined’</td>

    <td>5000</td>

</tr>

<tr>

    <td>waitForCondition</td>

    <td>typeof(window.ColdFusion.RichText) != ‘undefined’</td>

    <td>5000</td>

</tr>

<tr>

    <td>waitForCondition</td>

    <td>typeof(window.FCKeditorAPI) != ‘undefined’</td>

    <td>5000</td>

</tr>        

<tr>

    <td>waitForCondition</td>

    <td>typeof(window.ColdFusion.RichText.getEditorObject(‘content’))
!= ‘undefined’
</td>

    <td>5000</td>

</tr>            

<tr>

    <td>storeEval</td>

    <td> selenium.browserbot.getCurrentWindow().ColdFusion.RichText.
getEditorObject(‘content’).SetHTML(‘
&lt;div
id=”testSection”
&gt;
&lt;h2&gt;Welcome&lt;/h2&gt;
&lt;p&gt;Test page added.&lt;/p&gt; &lt;/div&gt;‘) </td>

    <td></td>

</tr>

<tr>

    <td>waitForElementPresent</td>

    <td>id=testSection</td>

    <td></td>

</tr>

 

Assuming that “content” is the name of your cftextarea, this is how you do it. You test for the “Coldfusion” object exists, then the “Coldfusion.RichText”, then the “FCKeditorAPI” and finally the actual richtext area. Once everything exists, you have to set the HTML of the FCKeditor. There is no input element to type into, so you have to use the FCKEditor setHTML method. To do that you have to use a storeEval command, and then you wait for the typed element you added to appear.

Hopefully this saves a few hours of work for someone else at some point.

Knowledge@Wharton Interviews Kevin Lynch

Knowledge@Wharton scored an interview with Adobe CTO Kevin Lynch. I think there’s a lot of great content in the article. The article is mostly concerned with Air, but the part I liked best is where the interviewer asks the question I’ve been wondering about for awhile chiefly:

Knowledge@Wharton: The AIR run time is available as a free download. The AIR Software Development Kit is available for free. How does Adobe make any money from this technology?

Kevin goes on to answer, read the whole article for his exact answer, but basically it comes down to the fact that Adobe uses it’s free products as a loss leader to encourage purchases of their other technologies including tooling and servers. He specifically includes ColdFusion in that.

I think this is another pointer to the fact that Adobe probably won’t be open sourcing or making free ColdFusion anytime in the near future. That might change if OpenBD and Railo gain any sort of traction. But I’m betting against them, as I have said before.