ฉันกำลังพยายามดำเนินการลากและวางในแอปพลิเคชันเชิงมุมของเราโดยใช้ Protractor Jasmine ฉันสามารถรับรายการต้นทางได้ แต่เมื่อการทดสอบดำเนินไป องค์ประกอบต้นทางจะถูกเลือกแต่ไม่มีอะไรเกิดขึ้นหลังจากนั้น การลากและวางจะไม่เกิดขึ้น ไม่มีข้อผิดพลาดแสดงในคอนโซล
สิ่งที่น่าสนใจเกี่ยวกับคอนเทนเนอร์ปลายทางคือรายการที่ปล่อยที่นี่สามารถปรับขนาดได้ตามความต้องการของผู้ใช้ นอกจากนี้ยังไม่มีสถานที่/พื้นที่ที่ทำเครื่องหมายไว้อย่างชัดเจนในคอนเทนเนอร์ปลายทางที่รายการที่ลากจะถูกดรอป! แต่คอนเทนเนอร์นั้นมีรหัส แม้ว่านั่นจะยังไม่ได้ช่วยที่นี่ก็ตาม
นี่คือรหัส:
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();
};
ฉันได้ลองใช้การดำเนินการ 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();
กรุณาแนะนำวิธีแก้ไขปัญหานี้
@ฟลอเรนต์บี. ฉันได้แนบรหัสพร้อมกับสคริปต์ของคุณที่นำเข้าแล้ว
ให้ JS_DRAG_DROP = need('./drag-drop.js');
ฟังก์ชั่น DragAndDropListItems (fdIndex: หมายเลข): เป็นโมฆะ {
/*
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();
};