空手道 UI 拖放[重复]

问题描述 投票:0回答:1

我正在研究 KarateUI 的可能性。我尝试使用框架的拖放功能。 我使用了带有可拖动元素的页面https://www.seleniumeasy.com/test/drag-and-drop-demo.html,但我的脚本无法在其上运行。我的脚本有什么问题吗?这是:

mouse().move('{div/span}Draggable 1').down().move('#mydropzone').up()

我还在 IDE 的控制台中看到下一个日志

16:11:40.196 [ForkJoinPool-1-worker-1] DEBUG c.intuit.karate.driver.DriverOptions - >> {"method":"Input.dispatchMouseEvent","params":{"type":"mouseMoved","x":31,"y":820},"id":16}
16:11:40.200 [nioEventLoopGroup-2-1] DEBUG c.intuit.karate.driver.DriverOptions - << {"id":16,"result":{}}
16:11:40.203 [ForkJoinPool-1-worker-1] DEBUG c.intuit.karate.driver.DriverOptions - >> {"method":"Input.dispatchMouseEvent","params":{"type":"mousePressed","x":31,"y":820,"button":"left","clickCount":1},"id":17}
16:11:40.234 [nioEventLoopGroup-2-1] DEBUG c.intuit.karate.driver.DriverOptions - << {"id":17,"result":{}}
16:11:40.234 [ForkJoinPool-1-worker-1] DEBUG c.intuit.karate.driver.DriverOptions - >> {"method":"Input.dispatchMouseEvent","params":{"type":"mouseMoved","x":231,"y":827},"id":18}
16:11:40.242 [nioEventLoopGroup-2-1] DEBUG c.intuit.karate.driver.DriverOptions - << {"id":18,"result":{}}
16:11:40.242 [ForkJoinPool-1-worker-1] DEBUG c.intuit.karate.driver.DriverOptions - >> {"method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","x":231,"y":827,"button":"left","clickCount":1},"id":19}
16:11:40.250 [nioEventLoopGroup-2-1] DEBUG c.intuit.karate.driver.DriverOptions - << {"id":19,"result":{}}
automation karate
1个回答
0
投票

拖放实际上很难正确执行,因此我建议通过 JavaScript 来完成此操作。使用空手道执行 JS 实际上非常简单:

* driver 'https://www.seleniumeasy.com/test/drag-and-drop-demo.html'
* script("var myDragEvent = new Event('dragstart'); myDragEvent.dataTransfer = new DataTransfer()")
* waitFor('{}Draggable 1').script("_.dispatchEvent(myDragEvent)")
* script("var myDropEvent = new Event('drop'); myDropEvent.dataTransfer = myDragEvent.dataTransfer")
* script('#mydropzone', "_.dispatchEvent(myDropEvent)")
* screenshot()

因此,对一些内部结构有一点了解 - 例如HTML5

DataTransfer
API - 您几乎可以做任何事情。我认为在浏览器中自动化复杂的端到端用户交互时,在这种情况下“改变规则”是很好的。

您当然可以将拖放操作包装成空手道中的可重用函数,只需记住“DOM JS”以纯文本形式发送到浏览器

请参阅文档:https://github.com/intuit/karate/tree/master/karate-core#function-composition

编辑:对于那些寻找在 DOM 上使用 JS 的其他示例的人:

  1. https://stackoverflow.com/a/60618233/143475
  2. https://stackoverflow.com/a/61478834/143475
  3. https://stackoverflow.com/a/66677401/143475
  4. https://stackoverflow.com/a/67701399/143475
  5. https://stackoverflow.com/a/67629911/143475
  6. https://stackoverflow.com/a/76698661/143475
© www.soinside.com 2019 - 2024. All rights reserved.