How to implement Selenium test cases for canvas




The reasons there are no methods like Node.doubleClick are several fold:

  • the behavior might be different at different points in the node because GraphObjects within the node’s visual tree might define their own click behavior (example: context click on ports in the Dynamic Ports sample)
  • there are other expected side-effects besides just calling the node’s GraphObject.click (or doubleClick or contextClick) event handler function, including selection and raising DiagramEvents
  • the node might not be visible, for any number of reasons, so users would not be able to click on the node, making your test less realistic than it could be

The benefit of actually simulating InputEvents is that it goes through the actual process of choosing and running tools. So it will actually start the ContextMenuTool or ClickSelectingTool, as appropriate.


Our internal tests that exercise ContextMenuTool do things like:
      test.mouseDown(new go.Point(100, 100), { timestamp: 0, button: 2 });Â  // right mouse button on node N3<br />      test.mouseUp(new go.Point(100, 100), { timestamp: 100, button: 2 });

This is followed by a wait for the diagram to be updated to show the context menu, and then:

      test.mouseDown(new go.Point(135, 110), { timestamp: 1000 });Â  // left click on first context menu button<br />      test.mouseUp(new go.Point(135, 110), { timestamp: 1200 });

Â