Month: October 2008

Introducing… jsbridge

Posted by on October 28, 2008

I started working on this library months ago and it’s been getting some use already. I spoke about it a bit at Mozilla Summit and as a result there was a post on Ajaxian, but for the most part I’ve been holding off on promoting it until I solidified the API and pushed out a solid release.

jsbridge is a Python to JavaScript translation interface for Mozilla applications. It’s implemented as an extension and can be dynamically installed and launched in a new “clean” profile using mozrunner.

You can call functions and set variables in any window in any scope from Python and those objects are returned and represented as Python objects (which are just classes that inherit from Python base types). There are obvious limitations for assignment and representations in Python, you can really only send objects over the bridge that can be JSON serialized, but it does support assignments by reference so you can move around and manipulate anything that’s already there.

But the most interesting feature is the event system. The event system is available as a resource from inside the Mozilla environment (in other words you can import it from your Firefox extension). Events fired on the JavaScript end are serialized as JSON and sent to the Python side. This means you can add listeners in Python to events fired from the Mozilla JavaScript environment.

This is a big deal. It means we can write significantly cleaner tools. We can now create tools solely as Firefox extensions that don’t require any special Python code to run, but have code that checks if jsbridge is installed and send pertinent events over the bridge for continuous integration. No more printing to console and parsing in Python, no more outputting to log files and parsing them, no more scripts calling scripts and OH MAN MY HEAD HURTS!

The documentation has some great examples.

For a little snippet of the events system in the wild here is some new mozmill Python code that sends all the events to the Python logger.

import logging
logger = logging.getLogger("mozmill")
 
from jsbridge import events
 
class LoggerListener(object):
    cases = {
        'mozmill.pass':   lambda obj: logger.debug('Test Pass: '+repr(obj)),
        'mozmill.fail':   lambda obj: logger.error('Test Failure: '+repr(obj)),
    }
 
    class default(object):
        def __init__(self, eName): self.eName = eName
        def __call__(self, obj): logger.info(self.eName+' :: '+repr(obj))
 
    def __call__(self, eName, obj):
        if self.cases.has_key(eName):
            self.cases[eName](obj)
        else:
            self.cases[eName] = self.default(eName)
            self.cases[eName](obj)
 
events.add_global_listener(LoggerListener())
logging.basicConfig(level=logging.ERROR)

Ubiquity command for docs.python.org

Posted by on October 23, 2008

Ubiquity rocks! A month or so ago I completely removed the search box from Firefox and started solely using ubiquity for searches.

The one thing that I really missed was a python doc search that I used to have for the search box. For a while I just used the awesome bar to perform google and history searches for python docs but that basically broke when Python 2.6 was released since all the old docs.python.org urls that google returns break because 2.6 has completely new docs provided by Sphinx.

So today I took a break from my “normal” work to write a ubiquity command to bring up the search page from docs.python.org for your input text. You can see the source here and you should be able to install it by viewing this blog post.

In the future I’d like to do better previews of the searches but I can’t seem to find any web API for searching docs.python.org.

MozMill Beta2 Released

Posted by on October 13, 2008

Last week we finished up the Beta2 Release for MozMill.

You can install it from AMO.

We’ve been gathering feedback from our Beta1 release and pushed out another incremental beta release before the big push for MozMill 1.0 RC1.

One important thing we did was improve the inspector workflow. It’s much smother clicking on an element and coming back to the Inspector. The inspector also gives you much more information now, including what document you should be passing the Elem you create and what method you should use to create a controller for the window you’re testing.

Lot’s of bug fixes, special thanks to Tony, Tracy and a big hug to Farhad for feature suggestions and filing bugs against beta1.

This release does not include the new framework that hooks up to jsbridge, and therefor isn’t ready for full continuous integration, that’s now in trunk getting worked on for the RC1 release.

Windmill 0.9.1 Released

Posted by on October 13, 2008

I didn’t think we’d be doing any notable windmill releases until 1.0. Boy was I wrong!

Seriously Faster

On Wednesday Adam messaged me and said that the windmill startup time was too slow. He was right, we’ve know about this for a while but hadn’t put a lot of serious thought in to how we could reduce it.
The issue here was was that we have about 50 JavaScript files that need to get loaded for windmill to start.

Enter windmill-compressor, a new url namespace we added that concats all the js windmill needs in to one file and minifies it. We do this dynamically when windmill starts up, because adding a “build” step would just be too….. Java.

That reduced the startup time from 5-10 seconds to around 2 seconds. But that wasn’t good enough. We saw that most of that startup time was blocking waiting for the compressor to finish, so I threaded it when we start the windmill service and it does the compression while we wait for the browser to start up.

In all, windmill startup times are about 10x faster than 0.9!

Adam also decided to make our page load wait code a bit more aggressive which made not only startup times faster but all of our tests!

Native JavaScript Test Framework

We tied up the loose ends on the JavaScript testing framework and it can now shutdown all of windmill in it’s own teardown, hello continuous integration for native JavaScript tests :)

This was the last thing holding us back from promoting this along side the Python test authoring library.

We Love Firebug

In 0.9 we introduced Firebug Lite integration for windmill on all browsers. But when you’re using Firefox you probably still want to use the full Firebug extension, which is easy enough to integrate since we use mozrunner for Firefox launching.

Windmill now has a “firebug” command line argument that installs the full Firebug
extension when launching Firefox.