Skip to content

Commit

Permalink
reduce viewport size on screenshots for popup to make them slightly f…
Browse files Browse the repository at this point in the history
…aster
  • Loading branch information
djahandarie committed Jan 1, 2025
1 parent c5fcaf7 commit 689720a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/playwright/visual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ test.describe('popup', () => {

console.log('Open popup-tests.html');
await page.goto(pathToFileURL(popupTestsPath).toString());
await page.setViewportSize({width: 1000, height: 4500});
await page.setViewportSize({width: 700, height: 500});
await expect(page.locator('id=footer')).toBeVisible();
await page.keyboard.down('Shift');
});
Expand All @@ -127,26 +127,30 @@ test.describe('popup', () => {
console.log(test_name);

// Find the test element
const test_locator = page.locator('.hovertarget').nth(i - 1);
const hovertarget_locator = page.locator('.hovertarget').nth(i - 1);

const box = (await test_locator.boundingBox()) || {x: 0, y: 0, width: 0, height: 0};
const testcase_locator = hovertarget_locator.locator('..');

const expectedState = (await test_locator.locator('..').getAttribute('data-expected-result')) === 'failure' ? 'hidden' : 'visible';
await testcase_locator.scrollIntoViewIfNeeded();

const box = (await hovertarget_locator.boundingBox()) || {x: 0, y: 0, width: 0, height: 0};

const expectedState = (await testcase_locator.getAttribute('data-expected-result')) === 'failure' ? 'hidden' : 'visible';

try {
const frame_attached = page.waitForEvent('frameattached', {timeout: 5000});
await page.mouse.move(box.x - 5, box.y - 5); // Hover near the test
await page.mouse.move(box.x + 15, box.y + 15, {steps: 10}); // Hover over the test
await page.mouse.move(box.x + 15, box.y + 15); // Hover over the test
if (expectedState === 'visible') {
const popup_frame = await frame_attached;
await (await /** @type {import('@playwright/test').Frame} */ (popup_frame).frameElement())
.waitForElementState(expectedState, {timeout: 500});
.waitForElementState(expectedState, {timeout: 1000});
} else {
expect(
await Promise.race([
frame_attached,
new Promise((resolve) => {
setTimeout(() => resolve('timeout'), 2000);
setTimeout(() => resolve('timeout'), 1000);
}),
]),
).toStrictEqual('timeout');
Expand Down

0 comments on commit 689720a

Please sign in to comment.