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?