[TIP] ANN: Nose Plugin to run JavaScript tests

Guido Wesdorp johnny at johnnydebris.net
Mon Feb 16 04:40:04 PST 2009

Kumar McMillan wrote:
> It's still experimental so if anyone has a suite of JavaScript tests
> please let me know if it works or not.  There is some support for
> JavaScript libraries that are tied to the DOM of a browser.
Hm, I'm working on a somewhat similar application at the moment, 
although a bit more involved, perhaps it makes sense to join forces somehow?

The idea is this: I'm using python-spidermonkey to build up a web 
browser environment (window basically) using a combination of pure JS 
libs (e.g. a DOM l. 2 lib) and Python libs (e.g. lxml for xpath and 
xslt). Currently I have support for XMLHttpRequest, XPath, XSLT and of 
course basic DOM l. 2 (mostly complete) and l. 0 (incomplete, but 
usable). In the future, I hope to be able to provide at least one, but 
perhaps more, complete browser APIs to test against...

A small example (taken from the unit tests):

b = browser.Browser(
        {'/': '''\
    <title>test page</title>
  <body onload="window.foo = 1">
assert b.eval('window.foo') == 1

As you can see, you can instantiate a Browser object (should be named 
BrowserWindow I guess), and pass in some server object (a simple object 
that implements a single method to load resources from the (virtual?) 
server), then call 'initialize' to have the HTML loaded and parsed, and 
the onload called. After this, you can call the 'eval' method to 
evaluate JavaScript code in the environment.

Currently it's still somewhat rudimentary, although already I use it for 
testing a rather complex application built using the YUI libs.

I hope I can build a small community to help me complete this, as you 
may understand it will not be a small task to implement full browser 
APIs, for instance implementing event handling etc. is quite involved...

Anyway, if you're interested in the application, check  out


If you're interested in helping out, even better! In that case drop me a 



P.S. For a simpler solution, which resembles your idea but then 
implemented using SpiderMonkey and py.test, see 
http://johnnydebris.net/svn/projects/jsbase (the conftest in the 
directory can be used for your own project, the unit tests eat their own 

More information about the testing-in-python mailing list