Some Changes

This commit is contained in:
2025-04-16 04:53:46 +00:00
parent e781643183
commit 609fc55ebe
13 changed files with 117 additions and 44 deletions

View File

@@ -6,7 +6,7 @@ const screenshotDir = 'screenshots';
fs.mkdirSync(screenshotDir, { recursive: true });
// Aisle coordinates (shared between tests)
const aisleCoordinates = [
const aisleCoordinates = [
{ x: 191, y: 237 },
{ x: 271, y: 238 },
{ x: 301, y: 170, button: 'right' },
@@ -133,23 +133,49 @@ const aisleCoordinates = [
*/
async function drawOrDeleteAisles(page, coordinates, action) {
console.log(`${action === 'create' ? 'Creating' : 'Deleting'} aisles...`);
const startTime = Date.now(); // Start measuring time
for (const { x, y, button = 'left' } of coordinates) {
console.log(`${action === 'create' ? 'Creating' : 'Deleting'} at (${x}, ${y})`);
await simulatePointerClick(page, x, y, button);
// Group coordinates into smaller batches to reduce overhead
const batchSize = 10; // Adjust based on application performance
for (let i = 0; i < coordinates.length; i += batchSize) {
const batch = coordinates.slice(i, i + batchSize);
// Add a small delay between clicks to ensure proper interaction
await page.waitForTimeout(300); // Adjust timeout if necessary
// Process each batch
for (const { x, y, button = 'left' } of batch) {
console.log(`${action === 'create' ? 'Creating' : 'Deleting'} at (${x}, ${y})`);
await simulatePointerClick(page, x, y, button);
// Wait for the element to disappear (if applicable)
if (action === 'delete') {
try {
await page.waitForSelector(`[data-aisle-coordinates="${x},${y}"]`, { state: 'hidden', timeout: 1000 });
} catch (error) {
console.warn(`Element at (${x}, ${y}) was not found or already deleted.`);
}
}
}
// Add a small delay after each batch to allow the application to catch up
await page.waitForTimeout(500); // Reduced delay compared to individual clicks
}
// Finalize aisle creation with right-click (only for creation)
if (action === 'create') {
// Finalize aisle creation with right-click
console.log('Finalizing aisle creation...');
await simulatePointerClick(page, 100, 160, 'right'); // Right-click to finalize
}
// Log total time taken
const endTime = Date.now();
console.log(`Finished ${action === 'create' ? 'creating' : 'deleting'} aisles in ${(endTime - startTime) / 1000} seconds.`);
}
/**
* Simulates a pointer click at specific coordinates.
* @param {Object} page - Playwright page object
* @param {Number} x - X-coordinate
* @param {Number} y - Y-coordinate
* @param {String} button - Mouse button ('left', 'right', or 'dblclick')
*/
async function simulatePointerClick(page, x, y, button = 'left') {
// Move to the desired position
@@ -187,7 +213,6 @@ async function setupCanvasAndTools(page, toolSelector) {
console.log('Moving canvas to the top position...');
const canvas = page.locator('canvas').first();
const canvasBox = await canvas.boundingBox();
if (!canvasBox) {
throw new Error('Canvas bounding box not found. Ensure the canvas is visible.');
}
@@ -199,15 +224,8 @@ async function setupCanvasAndTools(page, toolSelector) {
// Simulate a drag action to move the canvas
await page.mouse.move(startX, startY);
await page.mouse.down();
// Move the mouse down while dragging
await page.mouse.move(startX, startY + 100, {
steps: 20, // Smooth movement
});
// Simultaneously scroll the page (if needed)
await page.mouse.move(startX, startY + 100, { steps: 20 }); // Smooth movement
await page.mouse.wheel(0, 500); // Scroll down 500px
await page.mouse.up();
// 5. Select the appropriate tool (e.g., Aisle or Delete)