Thursday, September 18, 2008

Selenium IDE extension: decorateEventHandler

I was writing a Selenium IDE extension so that clicking on certain kinds of links would record a custom command instead of the default "click" command. In my ide-extensions.js file, I had written:

Recorder.decorateEventHandler(
    'clickLocator',
    'click',
    function (handler) {
        return function (event) {
            this.record('testingIt', 'inside', 'decorator');
            handler.call( this, event );
        };
    }
);

If all went right, when I clicked a link, it would record the command "testingIt inside decorator" and then record the typical "click" command. However, when starting Selenium IDE I got the message error loading Selenium IDE extensions: TypeError: handlers is undefined

After much trial and error and reading a good portion of the Selenium IDE source code, I noticed that when the 'clickLocator' EventHandler is defined, it's defined with capture : true. By specifying that option when calling decorateEventHandler, everything works as expected. This was the testing code that finally worked:

Recorder.decorateEventHandler(
    'clickLocator',
    'click',
    function (handler) {
        return function (event) {
            this.record('testingIt', 'inside', 'decorator');
            handler.call( this, event );
        };
    },
    { capture : true }
);

1 comments:

mndrix said...

Mohit, your best bet will be to visit the Selenium support page.