Winds of Change

Why is it that as soon as you finish something, you begin to think of ways to improve it?

I’m thinking of reworking the Selenium UI-Element map creation process, to make it more user-friendly. Today I was musing over the following guidelines / ideas / requirements, and have come up with a tentative solution:

  • Elements shouldn’t collide with one another. They should always be explicitly defined in some kind of namespace. Currently the namespace is being provided by a regular expression, which gives no guarantees against collisions.
  • Displaying the full URL as the surrogate namespace in the locator string is distracting. It’s much too long, and it isn’t that helpful … semantically, it is less informative about the UI specifier than I had hoped. Additionally, I need to be able to trace back from the locator directly to its UI element. The namespace should suggest the reason why the element is in that namespace. Instead of seeing ui=authors/d/shanediffily::topics(topic=Content), I’d rather see ui=allPages::topics(name=Content) .
  • There should be a more natural way to declare and use element-scoped variables and also global variables. The method I described before still seems too verbose and error prone.

Here’s the proposed solution:

var myMap = new UIMap();

// set a global map variable
myMap._topLevelTopics = [
    'Code'
    , 'Content'
    , 'Culture'
    , 'Design'
    , 'Process'
    , 'User Science'
];

// declare a pageset and associate with a regexp
myMap.addPageset('allPages', '.*',
    'covers all website pages');

// add an element to a specific pageset
myMap.addElement('allPages', {
    name: 'topic'
    , description: 'sidebar links to topic categories'
    , args: [
        {
            name: 'name'
            , description: 'the name of the topic'
            , defaultValues: myMap._topLevelTopics
        }
    ]
    , getXPath: function(args) {
        return this._listXPath +
            “/a[text()='” + args['name'] + “']”;
    }
    // maintain testcases for getXPath()
    , testcase1: {
        args: { name: 'foo' }
        , xhtml: '<div id=”topiclist><ul>'
            + '<li><a expected-result="1">foo</a></li>'
            + '</ul></div>'
    }
    // set a local element variable
    , _listXPath: “//div[@id='topiclist']/ul/li”
});

The UIMap object is initialized from the very start, so there’s no need to remember to do so at the bottom of the file. First, pagesets are declared. Then UI elements can be associated to them. Global variables are accessed using the name of the map variable (myMap in this case), and local variables are accessed using this.

Having testcases associated per UI element can ease their maintenance. Any object whose name starts with testcase will be considered a testcase. All tests can be run upon starting the Selenium IDE, which would report on any failures.

What do you think? It may take a while to rework the code, and I’d have to redo the work done previously to create map files.

Leave a Reply


Bad Behavior has blocked 864 access attempts in the last 7 days.