MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / dragAndDrop

Method dragAndDrop

lib/helper/Playwright.js:1595–1615  ·  view source on GitHub ↗

* * ```js * // specify coordinates for source position * I.dragAndDrop('img.src', 'img.dst', { sourcePosition: {x: 10, y: 10} }) * ``` * * > When no option is set, custom drag and drop would be used, to use the dragAndDrop API from Playwright, please set options, for example `force

(srcElement, destElement, options)

Source from the content-addressed store, hash-verified

1593 *
1594 */
1595 async dragAndDrop(srcElement, destElement, options) {
1596 const src = new Locator(srcElement)
1597 const dst = new Locator(destElement)
1598 const context = await this._getContext()
1599
1600 if (options) {
1601 return context.dragAndDrop(buildLocatorString(src), buildLocatorString(dst), options)
1602 }
1603
1604 const _smallWaitInMs = 600
1605 await context.locator(buildLocatorString(src)).hover()
1606 await this.page.mouse.down()
1607 await this.page.waitForTimeout(_smallWaitInMs)
1608
1609 const destElBox = await context.locator(buildLocatorString(dst)).boundingBox()
1610
1611 await this.page.mouse.move(destElBox.x + destElBox.width / 2, destElBox.y + destElBox.height / 2)
1612 await context.locator(buildLocatorString(dst)).hover({ position: { x: 10, y: 10 } })
1613 await this.page.waitForTimeout(_smallWaitInMs)
1614 await this.page.mouse.up()
1615 }
1616
1617 /**
1618 * {{> refreshPage }}

Callers

nothing calls this directly

Calls 2

_getContextMethod · 0.95
buildLocatorStringFunction · 0.85

Tested by

no test coverage detected