Hi,
I am trying to test application under test having GoJS canvas on it with Protractor .
I have seen already existing blogs and come across : Simulating Input Events .
I am trying to automate same sample application with Simple test case : dragging ‘alpha’ from palette to canvas
i Checked the ‘View this sample page’s source in-page’ , to simulate the Similar stuff in my protractor test (MyRobotTest.js) i have included go.js and Robot.js in my automation repository.
when i am running this , i am getting Error: ReferenceError: window is not defined in go.js
anything that i am missing to setup,
Note : i am not calling MyRobotTest.js from HTML,
can anyone please suggest any pointers if already tried protractor UI automation tool to test go js. thanks in advance
MyRobotTest.js code :
require(‘./Robot.js’);
require(‘./go.js’);
module.exports = function () {
this.myinit = function () {
var $ = go.GraphObject.make;
function showProperties(e, obj) { // executed by ContextMenuButton
var node = obj.part.adornedPart;
var msg = "Context clicked: " + node.data.key + ". ";
msg += "Selection includes:";
myDiagram.selection.each(function (part) {
msg += " " + part.toString();
});
document.getElementById("myStatus").textContent = msg;
}
function nodeClicked(e, obj) { // executed by click and doubleclick handlers
var evt = e.copy();
var node = obj.part;
var type = evt.clickCount === 2 ? "Double-Clicked: " : "Clicked: ";
var msg = type + node.data.key + ". ";
document.getElementById("myStatus").textContent = msg;
}
myDiagram =
$(go.Diagram, "myOverviewDiv", // must name or refer to the DIV HTML element
{
allowDrop: true, // must be true to accept drops from the Palette
nodeTemplate: $(go.Node, "Auto",
{
click: nodeClicked,
doubleClick: nodeClicked,
contextMenu: $(go.Adornment, "Vertical",
$("ContextMenuButton",
$(go.TextBlock, "Properties"),
{click: showProperties})
)
},
$(go.Shape, "Rectangle",
{fill: "lightgray"},
{portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer"}),
$(go.TextBlock,
{margin: 3},
new go.Binding("text", "key"))),
model: new go.GraphLinksModel([
{key: "Lambda"},
{key: "Mu"}
], [
{from: "Lambda", to: "Mu"}
]),
"undoManager.isEnabled": true
});
// a shared Robot that can be used by all commands for this one Diagram
robot = new Robot(myDiagram); // defined in Robot.js
// initialize the Palette that is on the left side of the page
myPalette =
$(go.Palette, "entityListPanel", // must name or refer to the DIV HTML element
{
nodeTemplate: myDiagram.nodeTemplate,
model: new go.GraphLinksModel([ // specify the contents of the Palette
{key: "Airplane"},
{key: "Airship"},
{key: "Businessman"}
])
});
}
this.dragFromPalette = function () {
// simulate a drag-and-drop between Diagrams:
var dragdrop = {sourceDiagram: myPalette, targetDiagram: myDiagram};
robot.mouseDown(5, 5, 0, dragdrop); // this should be where the Alpha node is in the source myPalette
robot.mouseMove(60, 60, 100, dragdrop);
robot.mouseUp(100, 100, 200, dragdrop); // this is where the node will be dropped in the target myDiagram
// If successful in dragging a node from the Palette into the Diagram,
// the DraggingTool will perform a transaction.
}
}