How can you access the main JavaScript scope of the browser in a functional test? For example, I want to obtain a reference to a Dojo widget and check it's attributes. In a browser JavaScript console I could for example run:

    dijit.registry.byId("widget_id")

...and get a reference to that widget. But how can I do this in the scope of a functional test? I've tried experimenting with the .eval() promise as well as just trying to access objects such as "window" in various promise callbacks but to no avail.

I'm sure there is a simple solution to this but I've not been able to find it.

有帮助吗?

解决方案

OK... I have this working:

.eval("window.dijit.registry.byId('MI1').id")
    .then(function(id) {
        console.log("Checking Menu Item ID: "+ id);
        assert(id == "MI1", "The menu item did not have the expected ID");
    })

However, I've noticed that the eval only works when it is returning a String. For example, I'd also like to be able to call ".setValue()" on a widget but this doesn't seem to work. In fact anything that returns an object seems to generate an error.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top