【问题标题】:WebDriverIO Drag and DropWebDriverIO 拖放
【发布时间】:2021-08-05 20:55:24
【问题描述】:

我还没有找到任何关于如何在 wdio v 7 中正确实现拖放的资源。API 中的内置拖放功能似乎不适用于 Chrome。我很好奇是否有人对 wdio v7 有任何解决方法,因为其他在线资源都是针对早期版本的。

【问题讨论】:

    标签: javascript drag-and-drop automated-tests webdriver-io


    【解决方案1】:

    我是这样阅读拖放的(我为咖啡脚本编写测试):

      # @coords_canvas - coordinates of the canvas on the screen
      mousedown_with_canvas: (x, y) ->
        # coordinates relative to the center of the canvas 
        x = x + @coords_canvas.left + @sizes_of_canvas.width / 2
        y = y + @coords_canvas.top + @sizes_of_canvas.height / 2
        browser.executeScript('e = new Event("mousedown");'+
        'e.clientX = arguments[0];'+
        'e.clientY = arguments[1];'+
        'e.altKey = false;'+
        'e.button = 0;'+
        'e.buttons = 1;'+
        'e.ctrlKey = false;'+
        'e.metaKey = false;'+
        'e.shiftKey = false;'+
        'window.document.querySelector("div.myDiagramDiv canvas").dispatchEvent(e);',
        [x, y, @max_canva])
    
      mousemove_with_canvas: (x, y) ->
        # coordinates relative to the center of the canvas 
        x = x + @coords_canvas.left + @sizes_of_canvas.width / 2
        y = y + @coords_canvas.top + @sizes_of_canvas.height / 2
        browser.executeScript('e = new Event("mousemove");'+
        'e.clientX = arguments[0];'+
        'e.clientY = arguments[1];'+
        'e.altKey = false;'+
        'e.button = 0;'+
        'e.buttons = 1;'+
        'e.ctrlKey = false;'+
        'e.metaKey = false;'+
        'e.shiftKey = false;'+
        'window.document.querySelector("div.myDiagramDiv canvas").dispatchEvent(e);',
        [x, y, @max_canva])
    
      mouseup_with_canvas: (x, y) ->
        # coordinates relative to the center of the canvas 
        x = x + @coords_canvas.left + @sizes_of_canvas.width / 2
        y = y + @coords_canvas.top + @sizes_of_canvas.height / 2
        browser.executeScript('e = new Event("mouseup");'+
        'e.clientX = arguments[0];'+
        'e.clientY = arguments[1];'+
        'e.altKey = false;'+
        'e.button = 0;'+
        'e.buttons = 1;'+
        'e.ctrlKey = false;'+
        'e.metaKey = false;'+
        'e.shiftKey = false;'+
        'window.document.querySelector("div.myDiagramDiv canvas").dispatchEvent(e);',
        [x, y, @max_canva])
    
      drag_and_drop: (point_1, point_2,
          status_of_select_elems = false) ->
        @mousedown_with_canvas(
          point_1.x,
          point_1.y
        )
        if status_of_select_elems
          browser.pause(1000)
        @mousemove_with_canvas(
          point_2.x,
          point_2.y
        )
        @mouseup_with_canvas(
          point_2.x,
          point_2.y
        )
    

    如果我能解决您的问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多