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 }
);

Saturday, September 6, 2008

The link you have used to enter the PayPal system is invalid

While testing a new payment feature for VGPC, I kept getting the error message "The link you have used to enter the PayPal system is invalid" after clicking on the Subscribe link. I had copied and pasted the link directly from PayPal's subscription button wizard. It worked fine against PayPal's production servers, but when I tried to point the link at PayPal's sandbox servers (by adding "sandbox" between "www." and "paypal.com"), I'd get this message.

I read all the developer's documentation about subscription buttons and painstakingly compared each request parameter. Everything was exactly as it was supposed to be. Then I realized, I had not changed the business parameter. The link was pointing at the sandbox, but the business email address was the one for production. As soon as I changed the business parameter so that it used my test business account from the sandbox, everything worked.

If the error message had said, perhaps, "The business name is invalid", it would have saved me a fair amount of time. Note to self: use descriptive error messages.