feat(test): Playwright testing integration (#4146)
This commit is contained in:
1 parent
856cd17531
commit
fe1a706446
26 files changed
+434
-215
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { Locator, Page } from 'playwright';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page - The page to simulate the drag on
|
||||
* @param locator - The locator of the element to perform the drag on
|
||||
*/
|
||||
|
||||
export async function simulateDrag(page: Page, locator: Locator) {
|
||||
const box = await locator.boundingBox();
|
||||
if (!box) {
|
||||
throw new Error('Element is not visible');
|
||||
}
|
||||
const { x, y, width, height } = box;
|
||||
const centerX = x + width / 2;
|
||||
const centerY = y + height / 2;
|
||||
|
||||
// Calculate the maximum possible movement distances within the element's bounds
|
||||
const maxMoveX = Math.min(100, x + width - centerX);
|
||||
const maxMoveY = Math.min(100, y + height - centerY);
|
||||
|
||||
const newX = centerX + maxMoveX;
|
||||
const newY = centerY + maxMoveY;
|
||||
|
||||
await page.mouse.move(centerX, centerY);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(newX, newY);
|
||||
await page.mouse.up();
|
||||
}
|
||||
Reference in new issue
Block a user