Automation 空手道UI拖放

Automation 空手道UI拖放,automation,karate,Automation,Karate,我正在研究卡拉特语的可能性。我尝试使用框架的拖放功能。 我使用了一个带有可拖动元素的页面,但我的脚本无法在上面运行。我的剧本怎么了?这是: 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 - >

我正在研究卡拉特语的可能性。我尝试使用框架的拖放功能。 我使用了一个带有可拖动元素的页面,但我的脚本无法在上面运行。我的剧本怎么了?这是:

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":{}}
16:11:40.196[ForkJoinPool-1-worker-1]调试c.intuit.karate.driver.DriverOptions->{“方法”:“输入.调度鼠标事件”,“参数”:{“类型”:“鼠标移动”,“x”:31,“y”:820},“id”:16}
16:11:40.200[nioEventLoopGroup-2-1]调试c.intuit.karate.driver.DriverOptions->{“方法”:“输入.调度MouseeEvent”,“参数”:{“类型”:“鼠标按下”,“x”:31,“y”:820,“按钮”:“左”,“点击计数”:1},“id”:17}
16:11:40.234[nioEventLoopGroup-2-1]调试c.intuit.karate.driver.DriverOptions->{“方法”:“输入.调度鼠标事件”,“参数”:{“类型”:“鼠标移动”,“x”:231,“y”:827},“id”:18}
16:11:40.242[nioEventLoopGroup-2-1]调试c.intuit.karate.driver.DriverOptions->{“方法”:“输入.调度MouseeEvent”,“参数”:{“类型”:“鼠标释放”,“x”:231,“y”:827,“按钮”:“左”,“点击计数”:1},“id”:19}

16:11:40.250[nioEventLoopGroup-2-1]调试c.intuit.karate.driver.DriverOptions-拖放操作实际上很难正确执行,因此我建议通过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()
因此,只要稍微了解一些内部的东西,比如HTML5API,你就可以做几乎任何事情。我认为在这种情况下,当涉及到在浏览器中自动化复杂的E2E用户交互时,“改变规则”是很好的

当然,您可以在空手道中将拖放功能包装成一个可重用的函数,请记住这一点

参考文件:

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


  • 实际上,拖放操作很难做到正确,所以我建议通过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()
    
    因此,只要稍微了解一些内部的东西,比如HTML5API,你就可以做几乎任何事情。我认为在这种情况下,当涉及到在浏览器中自动化复杂的E2E用户交互时,“改变规则”是很好的

    当然,您可以在空手道中将拖放功能包装成一个可重用的函数,请记住这一点

    参考文件:

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


  • 这确实是一个bug,我们正在研究它,感谢您的报告!这确实是一个bug,我们正在研究它,感谢您的报告!