How to simply run a script with Windmill browser testing

published Feb 02, 2012 02:53   by admin ( last modified Feb 02, 2012 02:53 )

Summary:

windmill -m test=./tests/test_1.py http://example.com

Windmill allows you to run tests against a web site through real browsers, including using Ajax technology. For example, you can operate a browser and windmills records everything you do as python code, which can the be run again, and altered.

Windmill can be used in large testing frameworks such as niteoweb.windmill (for Plone), but how do you just run a simple script with the code that has been generated by one's browsing about? Well, you canot easily do it from inside of python, down that path lies madness. While skirting madness, I realised that the simple way of running the python code was to have windmill run it for you:

windmill -m test=./tests/test_1.py http://example.com

The "-m" switch tells it to run Firefox. If you forget that switch it will run nothing while executing the code. The test sub command (I call it a sub command since it has no preceding dash) tells windmill where the python script is that was generated by windmill, and lastly the url is given as an argument to windmill. You need to set up a prefs.py file in the ~/.windmill directory (on Linux that is), with the following content:

MOZILLA_BINARY='/usr/bin/firefox'                                                               
MOZILLA_DEFAULT_PROFILE='~/.mozilla/firefox/'

 

Before resigning to runninng windmill from the command line, I tried to run my script it from within python, and here is an excerpt of that non functioning script with some explanations in it, important stuff in bold, using windmill 1.6, python 2.6 on Ubuntu 10.10:

import windmill
from windmill.authoring import setup_module, WindmillTestClient
from windmill.conf import global_settings
import sys

global_settings.START_FIREFOX = True # This makes it use Firefox
setup_module(sys.modules[__name__])

global_settings.TEST_URL ='http://example.com' #This does not work. Instead
# use ~./.windmill/prefs.py and add the line:
# TEST_URL ='http://example.com'
# (without the # in front)
client = WindmillTestClient(__name__)
client.waits.forPageLoad(timeout=u'20000')

client.click(xpath=u"//div[@id='content']/table/tbody/tr[1]/td/a/img")
# Click does not work, according to the debugger it does not exist. MouseUp does.
# Bailing out, avoiding madness