Cypress實現拖拽

coffee~發表於2024-10-26

使用Cypress內建的trigger方法實現拖拽一個元素到另一個同型別元素,實現排序

Typescript實現方法:

export function dragAndDrop(sourceLocator: string, targetLocator: string) {

const dataTranferMock = { setData: () => {}, setDragImage: () => {} }

cy.get(sourceLocator)

.trigger('pointerdown', { button: 0 })

.trigger('dragstart',{dataTransfer: dataTranferMock});

cy.get(targetLocator)

.trigger('dragover')

.trigger('drop');

}

相關文章