0
votes

http://theintern.io/: what is the best way to find dojo generated widget id's within functional tests, should I use webdriver "elementBy..." methods or maybe the "dijit/registry" or "dojo/query"?

Currently I am using the dijit registry to loop through all widgets until I find the one I'm interested in by some identifier like a label value or an attribute. But to do this I have just been iterating through the registry.toArray() collection, which feels a little rough.

e.g.

return this.remote.get(url)
    .execute(function(){
        // return the id of a widget by matching label text
        var widgetId = null;
        require(["dijit/registry"], function(registry){
            for (var i = 0; i < registry.toArray().length; i++){
                if (registry.toArray()[i].label && registry.toArray()[i].label === "someLabelText"){
                    widgetId =  registry.toArray()[i].get("id");
                    break;
                }
            }
        });
        return widgetId;
    })
    .elementById(id)
        .click()
        .end()
    .then(function(){
        //assert something
    })

UPDATE

Currently the application being tested avoids setting ids on any if its page elements because there are multiple of the same type of widgets used. Therefore finding them by other means is harder, but I've managed it by the above example and by using dojo/query, and of course I could use xpath. The above example is a rough example and I could have narrowed the search down a little.

I was just wondering what ideas people had for finding page elements, I have been concentrating on widget id's, but finding any attribute would be helpful. Perhaps there is a plugin to Intern that looks for text for example?

2
Hm, this is a little confusing. Could you speak a bit more about what you are trying to accomplish where you feel like you need to loop through all the page’s widgets, just to make sure that the right answer is provided for your situation?C Snover

2 Answers

0
votes

Are you searching through every widget because you don't know where to look or is it that you want to apply changes to all widgets with certain attributes? If so, then you can use dojo/query (http://dojotoolkit.org/reference-guide/1.9/dojo/query.html) to find the item you're looking for and then you can retrieve the Widget with registry.byId(id)

0
votes

What I find to work best if you want to view all widgets and disable them for example you can do the following and not need to know their Id's or types, unless as below you use this information for a specific purpose.

array.forEach(registry.toArray(), function(item, i) {
if(item.type != undefined && item.id != 'yourItem')
    item.set('disabled', true);
});