首页 > 解决方案 > 使用 gojs 实现 UI 自动化

问题描述

有没有关于如何彻底使用 gojs 进行 UI 自动化的文档?我只想将托盘上的控件拖放到画布上以创建流程图。请帮忙。我只需要指向一个教程或参考即可开始。

标签: selenium-webdriverautomated-testsselenium-chromedrivergojs

解决方案


我不确定您到底要什么,但是您是否使用 Robot 类来模拟用户输入? https://gojs.net/latest/extensions/Robot.html

// a shared Robot that can be used by all commands for this one Diagram
robot = new Robot(myDiagram);  // defined in Robot.js

然后可以执行以下操作:

function clickLambda() {
    var lambda = myDiagram.findNodeForKey("Lambda");
    if (lambda === null) return;
    var loc = lambda.location;

    // click on Lambda
    robot.mouseDown(loc.x + 10, loc.y + 10, 0, { });
    robot.mouseUp(loc.x + 10, loc.y + 10, 100, { });

    // Clicking is just a sequence of input events.
    // There is no command in CommandHandler for such a basic gesture.
}

或者:

function dragFromPalette() {
    // 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.
}

推荐阅读