使用 nightwatch 进行拖放

Drag and drop using nightwatch

我正在尝试使用带硒的 nightwatch 拖放功能将元素拖放到特定位置,但是当我将超过 i 个元素放到同一个可放置元素时,它会重叠。

var dragAndDrop = require('html-dnd').codeForSelectors;  
this.dragModule = function (draggable, droppable, posX, posY) {
    browser.pause(3000);
    var dndSimulateConfig = { dropOffset: [posX, posY] };
    browser
      .execute(dragAndDrop, [draggable, droppable, dndSimulateConfig])
      .pause(2000);
  };

它不应该重叠我特别想要的坐标

locator1: can be xpath (or cssSelector) of your first element you want to drag locator2: can be xpath (or cssSelector ) is where you want to drop

this is tried and tested code, might be you need to little modify but it's working great for me.

return browser
    .useXpath()
    .moveToElement(locator1, XOffset1, Yoffset1)
    .pause(100) // if you want to give wait
    .mouseButtonDown(0) // press click, down
    .moveToElement(locator2, XOffset2, Yoffset2) // move to element
    .mouseButtonUp(0); // press release , up

read here docs- http://nightwatchjs.org/api and search for "moveToElement"

how to call:

myFunction moveToSpecificElement(locator, x, y) {
  return browser
  .moveToElement(locator, x, y, function (result) {
    this.assert.equal("your assertion goes here");
  });
}

我使用的是 html-dnd 版本 1.2.0。所以拖放是重叠的。使用任何旧版本 'html-dnd' 都可以。