I am writing a script for drag and drop reordering question type by using cypress where I use plugin as cy.get(sourceElement).drag(targetElement)
.
I found the source element and target element but that element is not drag and drop. Can aAnyone share the solution for this?
I drag the element from source point and drop it in target point but it doesn’t happen.
This is my code
let collection1 = [];
const origValueArray = [];
cy.get('.draggable__item').then($items => {
let collection = [];
$items.each((index, el) => {
const attrValue = el.getAttribute('data-rbd-draggable-id');
collection.push(attrValue);
});
const sortedCollection = [...collection].sort();
cy.log(sortedCollection);
cy.get('div[data-rbd-drag-handle-draggable-id]').then($items1 => {
$items1.each((index, el) => {
const attrValue1 = el.getAttribute('data-rbd-drag-handle-draggable-id');
cy.log(attrValue1);
collection1.push(attrValue1);
});
// Ensure all collections are built before proceeding
cy.wrap(sortedCollection).then(sortedArray => {
sortedArray.forEach((el, index) => {
cy.log(collection1);
cy.get(`div[data-rbd-draggable-id="${el}"]`, { timeout: 10000 }).should('be.visible').then($el => {
cy.get(`div[data-rbd-drag-handle-draggable-id="${collection1[index]}"]`, { timeout: 10000 }).should('be.visible').then($target => {
cy.wrap($el).dragTo($target);
});
});
});
});
});
});