You are not logged in Log in Join
You are here: Home » Members » roeder » Quick TestRecorder tutorial » View Document

Log in
Name

Password

 

Quick TestRecorder tutorial

I will use a fresh installation of Plone 2.1.2 with no customisations to demonstrate the use of TestRecorder to produce Selenium and DocTest functional testing code.

The excercise consists of recording a new user joining a Plone site.

In a perfect world, this would produce a working functional test that I would only need to copy and paste into my preferred functional test tool, and can could run continously without having to modify anything further.

Getting TestRecorder

You need to get TestRecorder out of the SVN repository of Zope Corporation:

svn://svn.zope.org/repos/main/zope.testrecorder/trunk

If you run into trouble getting TestRecorder, have a look at the The Zope Public Subversion Repository:

http://www.zope.org/DevHome/Subversion/FrontPage

Installing TestRecorder

Here are the instructions for installation of TestRecorder in Zope 2, taken from the README.txt of TestRecorder.

"For a Zope 2 system, drop this package into the products directory of the Zope instance and restart the instance. After restart, it will be possible to add a Test Recorder object in the ZMI. The Test Recorder Zope object mainly provides the ability to traverse to the html and .js files that make up the recorder."

Add the Test Recorder object in your Plone site through the ZMI, and click on it. You should give it an id that you can easily remember, like "testrecorder". This will turn out rather practical further along.

To start recording, click on the "Start the test recorder" link. A new window containing to frames will pop up.

Recording the test

In the top frame, I entered the address of the Plone site "http://localhost:8080/Plone" and clicked on "Go" button to start the recording.

When I wanted to start the test by clicking the join link on the Plone site, I noticed that I was still logged in with the Manager user with whom I had added the Test Recorder object. What is even more startling is the fact that it is impossible to log out of a Plone site when you have logged in via the ZMI, unless you do so in the ZMI.

To work around this problem, I closed all brower windows and fired up Firefox again. By that time I realzed that I hadn't paid attention to what the exact URL for running the tests was, so I had to go back to the ZMI as a Manager, and restart the browser all over. As I recommended writing down the id of your test brower earlier, you'll have no problem of composing the right URL for accessing the recorder:

"http://localhost:8080/Plone/testrecorder/index.html"

Again, I entered the address of the Plone site "http://localhost:8080/Plone" in the upper frame and clicked on the "Go" button.

This time I was an anonymous user for Plone and started recording. I clicked on the join link in Plone site shown in the lower frame, and entered my personal information, and logged in.

Once I had finished recordung, I clicked on the "Stop Recording" button and was presented with the results of the test:

    Open url ''
    pen url 'http://localhost:8080/TestRecorder'
    Click link 'Join'
    Open url 'http://localhost:8080/TestRecorder/join_form'
    Click submit button 'unknown'
    Submit form 'unknown'

Test Recorder offers two export formats for the tests, Python DocTest format and Selenium Test format.

This is what the DocTest rendering looks like:

    ==============================================================================
    Doctest generated Sun Feb 26 2006 20:26:52 GMT-0600 (Centre)
    ==============================================================================

    Create the browser object we'll be using.

        >>> from zope.testbrowser import Browser
        >>> browser = Browser()
        >>> browser.open('http://localhost')
        >>> browser.open('http://localhost/TestRecorder')
        >>> browser.getLink('Join').click()
        >>> browser.open('http://localhost/TestRecorder/join_form')
        >>> browser.getControl('Log in').click()

Looking a bit closer at the DocTest, you will find that the values entered while joining the Plone site, like login name and email have not been captured by TestBrowser.

There are obviously still some limitations in Test Recorder which necessitate a manual second pass.

Now for the Selenium rendering, which is presented both as a quoted and unquoted HTML table.

open
open /TestRecorder
clickAndWait //a[@href='/TestRecorder/join_form']
open /TestRecorder/join_form
clickAndWait //input[@name='' and @value='Log in']

    <table border=1>
    <tr>
    <td>open</td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td>open</td>
    <td>/TestRecorder</td>
    <td></td>
    </tr>
    <tr>
    <td>clickAndWait</td>
    <td>//a[@href='/TestRecorder/join_form']</td>
    <td></td>
    </tr>
    <tr>
    <td>open</td>
    <td>/TestRecorder/join_form</td>
    <td></td>
    </tr>
    <tr>
    <td>clickAndWait</td>
    <td>//input[@name='' and @value='Log in']</td>
    <td></td>
    </tr>
    </table>

The results for the Selenium rendering don't contain the click on the join button, which are present in the DocTest rendering.

Conclusion

Currently , TestRecorder is only useful for recording a first raw test rendering. This is better than starting from scratch, and gives a structure to the test you'll then have to get straight either from within Selenium or from within DocTest.

There are other test recorders out there that you may want to give a try:

Selenium IDE

http://openqa.org/selenium-ide/

Selenium Recorder

http://seleniumrecorder.mozdev.org/