dragAndDrop在Chrome上不起作用

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

我正在尝试使用量角器Jasmine在我们的Angular应用程序上执行拖放操作。我能够掌握源项目,但是在测试运行时,选择了源元素,但是此后什么也没有发生。拖放操作不会发生。控制台中未显示任何错误。

关于目标容器的有趣之处在于,可以根据用户的意愿调整放置在此处的项目的大小。另外,在目标容器中没有明确标记的位置/区域,拖动的物品将在那里掉落!但是容器确实有一个ID。尽管这仍然没有帮助。

这里是代码:

let dragAndDrop = require('html-dnd').code;

.
.
.


function dragAndDropListItems(fdIndex: number): void {                                                 
    let dragElement = element.all(by.repeater('listDefinition in lists')).get(fdIndex); // Select the first repeater corresponding to the first List Item in the list

    let dragElementh5 = dragElement.all(by.css('a')).get(0); // Select the first List Item
    let printFD = dragElementh5.getText().then((text: string) => {
        console.log(text); // Print the innerHTML text from the chosen List Item to the Console
    });

    let finalDrop = element.all(by.css('[id="dashboardContainerDiv"]')).get(0);

    dragElement.click();
    browser.actions().dragAndDrop(dragElement, finalDrop).perform();

};

souce and destination location

Manual DragAndDrop

我也尝试过使用基于坐标的DragNDrop操作,但在每种情况下都相同。

其他尝试的选项包括:

    //browser.executeScript(dragAndDrop, dragElement, finalDrop); // Perform the drag and drop operation 

    //browser.driver.actions().dragAndDrop(dragElement, finalDrop).perform();

    //browser.actions().dragAndDrop(dragElement, { x: 400, y: 400 }).perform();      
   // browser.driver.actions().mouseDown(dragElement).mouseMove(finalDrop).mouseUp(finalDrop).perform();

请为这个问题提供解决方案。

@ FlorentB。我已将代码与您导入的脚本一起附加。

让JS_DRAG_DROP = require('./ drag-drop.js');

function dragAndDropListItems(fdIndex:number):void {

/*
let source = driver.find_element_by_css_selector("#drag")
target = driver.find_element_by_css_selector("#drop")
driver.execute_async_script(JS_DRAG_DROP, source, target)

# drag and drop an element by offset {x:500, y:200}
source = driver.find_element_by_css_selector("#drag")
driver.execute_async_script(JS_DRAG_DROP, source, None, 500, 200)

# drag and drop an element with a delay of 101ms before the drop
source = driver.find_element_by_css_selector("#drag")
target = driver.find_element_by_css_selector("#drop")
driver.execute_async_script(JS_DRAG_DROP, source, target, 0, 0, 101)
*/

 let source = element.all(by.repeater('listDefinition in 
 lists')).get(fdIndex); // Select the first repeater corresponding to the 
 first List Item in the list
let dragElementh5 = source.all(by.css('a')).get(0); // Select the first List 
Item
let printFD = dragElementh5.getText().then((text: string) => {
    console.log(text); // Print the innerHTML text from the chosen List Item 
    to the Console
});


//browser.driver.switchTo().frame('dashboardContainerDiv'); 

/*
let finalDropClass = element.all(by.css('[class="dashboard mb10"]')).get(0); 
let finalDropCon = 
finalDropClass.all(by.css('[id="dashboardContainerDiv"]')).get(0);
let finalDrop = 
finalDropCon.all(by.css('[id="dashboardContainerUl"]')).get(0);  
*/

let target  = element.all(by.css('[id="dashboardContainerDiv"]')).get(0);

//dragElement.click();

browser.executeScript(JS_DRAG_DROP, source, target); // Perform the drag and 
drop operation 
//browser.actions().dragAndDrop(dragElement, finalDrop).perform();

//browser.driver.actions().dragAndDrop(dragElement, finalDrop).perform();

//browser.actions().dragAndDrop(dragElement, { x: 400, y: 400 }).perform();      

// browser.driver.actions()。mouseDown(dragElement).mouseMove(finalDrop).mouseUp(finalDrop).perform();

};

angularjs google-chrome typescript drag-and-drop protractor
1个回答
0
投票

尝试

https://github.com/html-dnd/html-dnd

安装它并使用打字稿示例对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.