Testing Dojo web applications with Selenium
I jot down here some findings about testing Dojo web applications (with a lot of Dijit Widget!) using Selenium, just in case someone will need them.
- You have to find the right element to send an event. The DOM trees generated by Widgets are huge, with layer under layer. Sometimes it is necessary to read the code and decide which element is used by Dojo to receive which kind of event. Moreover, synthetic events are bad as it not be able to consistently updating the focused elements the way human interactions do, while Widgets heavily rely on this behavior. Some Widgets even refuse to react up on faux clicks.
The first one is to utilize native events implemented by all major web browsers. This approach should work well unless you encounter a bug in their implementation, or you are testing against an unpopular browser. It is quite straightforward to enable native events:
DesiredCapabilities capabilities = new DesiredCapabilities();
The second one, which will work for edge cases, is to use a robot. A robot can simulate human action as Operating System level. This means if the robot is trying to move the mouse, you will see on your screen that the pointer is moving. The drawback is that the executing machine need to have a display device regardless of being a physical machine or a virtual one (in other word, headless machine will not work). Another disadvantage is that you have to convert coordinates from window-relative into device-relative. To overcome this limitation, just run the browser in full screen mode. For example, with Chrome, we use “kiosk” command switch for full screen mode:
ChromeOptions options = new ChromeOptions();
And we control the robot like this:
Point location = input.getLocation();
int x = location.getX();
int y = location.getY();
Robot r = new Robot();
r.mouseMove(x + 10, y + 10);
Finally, Dijit Widget have a bug with touch event (Dojo manipulate browser’s events a lot, it even managing it own focusing behavior so it is really prone to bugs and browser’s compatibility. Make sure you have latest fixes and if things still happen, disable touch events in Chrome.
- From Google Chrome, type chrome://flags in the address bar, then press Enter.
- Scroll down to the "Enable Touch Events".
- Select the drop-down menu and select Disabled.
- Restart and enjoy Chrome!