拖放在量角器typescript中不起作用



我正在制作量角器打字脚本。我试图在网站上自动拖放,但无法做到这一点。

What all I have try:

let source=element(by.xpath("abc"));
let destinaton=element(by.xpath("xyz"));
1) await browser.driver.actions().dragAndDrop(await source.getWebElement(),await destinaton.getWebElement()).perform();
2) browser.actions().dragAndDrop(source, destinaton).perform();
3) await browser.driver.actions().mouseMove(await source.getWebElement()).
mouseDown(await source.getWebElement()).
mouseMove(await destinaton.getWebElement()).
mouseUp(await destinaton.getWebElement()).
perform();
4) await browser.driver.actions()
.mouseMove({x: srcx, y: srcy})
.mouseDown()
.mouseMove({x: destx, y:desty})
.mouseUp().perform();
5) var fs = require("fs");
var dnd_js = fs.readFileSync("/abc/drag_and_drop_helper.js");
browser.driver.executeScript(dnd_js+source+".simulateDragDrop({ dropTarget: "+destination+"});")
6) var dragAndDrop = require('html-dnd').code;
browser.driver.executeScript(dragAndDrop, source, destination);

上面提到的所有方法我都试过了,还有更多的方法,但都不起作用。它只悬停在源元素和目标元素上,而不拖动。

技术:

Typescript: 3.0.1量角器:7.0.0

如果周围有其他工作请帮助我。

我的问题发生在测试@angular/cdk拖放时。

我首先需要将鼠标移动到拖动元素,而不是直接将元素移动到目的地,我必须移动鼠标一些像素。

async dragAndDrop(dragElement: WebElement, dropElement: WebElement) {
await browser.actions().mouseMove(dragElement).perform();
await browser.actions().mouseDown(dragElement).perform();
await browser.actions().mouseMove({ x: 10, y: 0 }).perform();
await browser.actions().mouseMove(dropElement).perform();
await browser.actions().mouseUp().perform();
}

我结合了https://github.com/angular/protractor/issues/123和https://github.com/wilgert/angular-cdk-drag-drop-protractor-issue/blob/master/e2e/src/app.po.ts#L26

最新更新