Wednesday, January 19, 2011

Testing YUI DND with Selenium

If you happen to write some selenium tests for YUI based page you may notice that sometime selenium DND does not work.
This is because selenium sometime has error when computing the right X,Y of a component when using YUI layout manager.
This problem can be solved easily by overriding selenium JavaScript code that compute X,Y given a locator.

For example getElementPositionTop can be rewrite to something like that:

Selenium.prototype.getElementPositionTop = function(locator) {
    /**
     * Retrieves the vertical position of an element
     *
     * @param locator an element locator pointing to an element OR an element itself
     * @return number of pixels from the edge of the frame.
     */
    var element;
    if ("string" == typeof locator) {
        element = selenium.browserbot.findElement(locator);
    }
    else {
        element = locator;
    }
    var xy = selenium.browserbot.getCurrentWindow().YAHOO.util.Dom.getXY(element);
    return xy[1];
};

All the change should written to a file for example 'user-extensions.js' and selenium should be run with the cmd:


java -jar selenium-server.jar  -userExtensions user-extensions.js

That should solve the issue.



2 comments: