testcomplete-gojs-bridge
A minimal, CSP-safe bridge that lets TestComplete send simple JSON commands into a GoJS page and receive JSON replies back. It avoids eval and heavy object marshalling by communicating via DOM data-attributes on the diagram’s DIV. Prebuilt commands cover selection, centering, coordinate lookup, and node introspection. The bridge also exposes a change-stamp so you can deterministically wait for diagram updates.
coordsForText
Returns page-relative click coordinates for the node whose data.text matches. Also centers & selects the node before computing coords.
// TestComplete → Page
sendCommand(page, 'myDiagramDiv', {
type: 'coordsForText',
text: 'Alpha'
}, 5000);
// Page → TestComplete (response)
{ ok: true, x: 412, y: 286 }
coordsForKey
Same as coordsForText but targets a node by data.key. Prefer keys when texts aren’t unique.
sendCommand(page, 'myDiagramDiv', {
type: 'coordsForKey',
key: 2
}, 5000);
getNodeInfoByText
Returns a snapshot of node info (key, text, selection, bounds, view & page center). Fully recalculated at call time.
sendCommand(page, 'myDiagramDiv', {
type: 'getNodeInfoByText',
text: 'Beta'
}, 5000);
// → {
ok: true,
key: 2,
text: 'Beta',
selected: true,
location: { x: 42, y: 88 },
documentBounds: { x: 0, y: 0, w: 80, h: 40 },
viewCenter: { x: 210, y: 134 },
pageCenter: { x: 412, y: 286 }
}
getNodeInfoByKey
Same as above, but addressed by numeric key. Useful for stable regression specs.
sendCommand(page, 'myDiagramDiv', {
type: 'getNodeInfoByKey',
key: 4
}, 5000);
selectByText
Centers the node and sets it selected. Use when your app reacts to GoJS selection events.
sendCommand(page, 'myDiagramDiv', {
type: 'selectByText',
text: 'Alpha'
}, 5000);
selectByKey
Selects the node by key and scrolls it into view. Pair with a physical Click from TestComplete if needed.
sendCommand(page, 'myDiagramDiv', {
type: 'selectByKey',
key: 3
}, 5000);
centerByText
Only scrolls the node into view (no selection). Handy before capturing screenshots.
sendCommand(page, 'myDiagramDiv', {
type: 'centerByText',
text: 'Gamma'
}, 5000);
centerByKey
Viewport-center a node by key. Combine with coordsForKey to compute a guaranteed visible click point.
sendCommand(page, 'myDiagramDiv', {
type: 'centerByKey',
key: 1
}, 5000);
Change Stamp: data-diagram-updated
A timestamp attribute on the DIV that updates after moves, layouts, selection moves, and viewport changes. Wait on it to synchronize.
// TestComplete pseudo
var before = nowEpochMs();
// ... perform action that moves a node ...
waitForUpdate(page, 'myDiagramDiv', before, 5000); // → true when updated