Funittest tutorial

Before you can run the first complete example of using Funittest, you need to take the following hurdles:

Requirement 1: You need to install and run the Selenium RC server. Otherwise Funittest can't run functional tests in a browser, but will run in dry mode, which simply echoes the commands it receives without doing any real work.

Use the nightly build of Selenium RC 0.9.1 (selenium-remote-control-0.9.1-SNAPSHOT.zip 27-Dec-2006 01:49 8.8M):

Requirement 2: You need to have Funittest installed. Just make it available in your Python module path.

Requirement 3: You should print out and start to familiarize yourself with the Selenium: Selenium Core 0.8.2 Reference and the Module selenium :: Class selenium API documentation.

Accessing the Plone site

Funittest includes an interpreter that handles the communication with the Plone site via Selenium RC. The first step is to use the start command and then the open command. A new navigator window will open automatically and the Plone start page will be accessed.

from funittest import interpreter
interpreter.setBrowserURL("http://plone.org/")
interpreter.start()
interpreter.open("/")

Funittest comes with a full range of Logical Functional Models that can be used to pilot a Plone site. The Logical Functional Models are grouped by application features. The next example will show how to use the Logical Functional Model used for searching.

Searching for a text

The Logical Functional Model for searching a Plone site allows us to search for a text in the Plone site.

from funittest import interpreter
interpreter.setBrowserURL("http://plone.org/")
interpreter.start()
interpreter.open("/")
from funittest import logical
logical.cmfplone.search.search_text("Welcome to Plone")

The interpreter prints out exactly which commands are executed. We can take these commands and execute them ourselves. The result is the same.

from funittest import interpreter
interpreter.setBrowserURL("http://plone.org/")
interpreter.start()
interpreter.open("/")
interpreter.type("SearchableText", "Welcome to Plone")
interpreter.clickAndWait("//input[@value='Search']")