Test UI-Element Locators
addScript uimap
open ../tests/html/test_locators.html  
verifyText ui=pageset1::linksWithId() this is the first element
verifyText ui=pageset1::linksWithId(index=1) this is the first element
verifyText ui=pageset1::linksWithId(index=2) this is the*second*element
verifyText ui=pageset1::linksWithId(index=3) this is the third element
verifyText ui=pageset1::fourthLink() this is the fourth element
verifyText ui=pageset1::fifthLink() this is the fifth element
verifyText ui=pageset1::linksWithId()->//span exact:element
verifyText ui=pageset2::cell(text=theHeaderText) exact:theHeaderText
verifyText ui=pageset2::cell(text=theCellText) exact:theCellText
verifyEval map.getUISpecifierString(selenium.browserbot.findElement('id=firstChild'), selenium.browserbot.getDocument()) ui=pageset3::anyDiv()->/child::span
removeScript uimap  
var map = new UIMap();

map.addPageset({
    name: 'pageset1'
    , description: 'pageset1Desc'
    , paths: [ 'pageset1Path' ]
});

map.addElement('pageset1', {
    name: 'linksWithId'
    , description: 'link with an id attribute starting with "id"'
    , args: [
        {
            name: 'index'
            , description: 'index of the link, starting at 1'
            , defaultValues: []
        }
    ]
    , getLocator: function(args) {
        var indexPred = args.index ? '[' + args.index + ']' : "";
        return "//a[starts-with(@id, 'id')]" + indexPred;
    }
});

map.addElement('pageset1', {
    name: 'fourthLink'
    , description: 'the fourth link'
    , locator: 'id=foo:bar'
});

map.addElement('pageset1', {
    name: 'fifthLink'
    , description: 'the fifth link'
    , xpath: '//a[5]'
});

map.addPageset({
    name: 'pageset2'
    , description: 'pageset2Desc'
    , paths: [ 'pageset2Path' ]
});

map.addElement('pageset2', {
    name: 'cell'
    , description: 'a cell in the style table'
    , args: [
        {
            name: 'text'
            , description: 'the text content of the node'
            , defaultValues: []
        }
    ]
    , getLocator: function(args) {
        return "//table[@class='stylee']/descendant::"
            + this._contentMap[args.text];
    }
    , _contentMap: {
        'theHeaderText': 'th'
        , 'theCellText': 'td'
    }
});

map.addPageset({
    name: 'pageset3'
    , description: 'pageset3Desc'
    , pathRegexp: '.*'
});

map.addElement('pageset3', {
    name: 'anyDiv'
    , description: 'any div element'
    , locator: '//div'
    , getOffsetLocator: function(locatedElement, pageElement) {
        if (pageElement.parentNode == locatedElement) {
            return '/child::' + pageElement.nodeName.toLowerCase();
        }
        return null;
    }
});