From a5083738c8cdea57d4c16cfd24ee31dd3c5f2c81 Mon Sep 17 00:00:00 2001 From: astandrik Date: Sat, 28 Dec 2024 16:25:28 +0300 Subject: [PATCH] fix: tryfix safari clipboard --- .../tenant/summary/objectSummary.test.ts | 19 ++++++++----- tests/utils/clipboard.ts | 27 +++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/tests/suites/tenant/summary/objectSummary.test.ts b/tests/suites/tenant/summary/objectSummary.test.ts index cd053fdaa..83146c3f3 100644 --- a/tests/suites/tenant/summary/objectSummary.test.ts +++ b/tests/suites/tenant/summary/objectSummary.test.ts @@ -201,9 +201,7 @@ test.describe('Object Summary', async () => { ]); }); - test('Copy path copies correct path to clipboard', async ({page, browserName}) => { - test.skip(browserName === 'webkit', 'Clipboard API is not reliable in Safari'); - + test.only('Copy path copies correct path to clipboard', async ({page}) => { const pageQueryParams = { schema: dsVslotsSchema, database: tenantName, @@ -215,9 +213,18 @@ test.describe('Object Summary', async () => { const objectSummary = new ObjectSummary(page); await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.CopyPath); - await page.waitForTimeout(1000); - - const clipboardContent = await getClipboardContent(page); + // Wait for clipboard operation to complete + await page.waitForTimeout(2000); + + // Retry clipboard read a few times if needed + let clipboardContent = ''; + for (let i = 0; i < 3; i++) { + clipboardContent = await getClipboardContent(page); + if (clipboardContent) { + break; + } + await page.waitForTimeout(500); + } expect(clipboardContent).toBe('.sys/ds_vslots'); }); diff --git a/tests/utils/clipboard.ts b/tests/utils/clipboard.ts index 1b28a43e6..21e0d0044 100644 --- a/tests/utils/clipboard.ts +++ b/tests/utils/clipboard.ts @@ -3,12 +3,35 @@ import type {Page} from '@playwright/test'; export const getClipboardContent = async (page: Page): Promise => { await page.context().grantPermissions(['clipboard-read']); - return page.evaluate(async () => { + // First try the modern Clipboard API + const clipboardText = await page.evaluate(async () => { try { const text = await navigator.clipboard.readText(); return text; } catch (error) { - console.error('Failed to read clipboard:', error); + return null; + } + }); + + if (clipboardText !== null) { + return clipboardText; + } + + // Fallback: Create a contenteditable element, focus it, and send keyboard shortcuts + return page.evaluate(async () => { + const el = document.createElement('div'); + el.contentEditable = 'true'; + document.body.appendChild(el); + el.focus(); + + try { + // Send paste command + document.execCommand('paste'); + const text = el.textContent || ''; + document.body.removeChild(el); + return text; + } catch (error) { + document.body.removeChild(el); return ''; } });