2024-11-20 15:15:10 +01:00
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
|
import path, { dirname } from 'path';
|
|
|
|
|
import { fileURLToPath } from 'url';
|
2024-10-22 10:35:15 +02:00
|
|
|
|
2024-11-20 15:15:10 +01:00
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = dirname(__filename);
|
2024-10-22 10:35:15 +02:00
|
|
|
|
2024-11-20 15:15:10 +01:00
|
|
|
test('download a file', async ({ page, browserName }) => {
|
|
|
|
|
// https://github.com/microsoft/playwright/issues/13037
|
|
|
|
|
test.skip(browserName.toLowerCase() !== 'chromium',
|
|
|
|
|
`Test only for chromium!`);
|
2024-10-22 11:32:39 +02:00
|
|
|
|
2024-11-20 15:15:10 +01:00
|
|
|
await page.goto('/dashboard');
|
|
|
|
|
await page.locator('div').getByTestId("upload").setInputFiles([
|
|
|
|
|
path.join(__dirname, "assets", 'chatgpt.jpg'),
|
|
|
|
|
]);
|
|
|
|
|
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
|
|
|
|
await page.locator('.file-cell button').first().click();
|
|
|
|
|
const handle = await page.evaluateHandle(() => navigator.clipboard.readText());
|
|
|
|
|
const cid = await handle.jsonValue()
|
|
|
|
|
|
|
|
|
|
await page.locator('.download-input input').fill(cid);
|
|
|
|
|
// const page1Promise = page.waitForEvent('popup');
|
|
|
|
|
const downloadPromise = page.waitForEvent('download');
|
|
|
|
|
await page.locator('.download-input + button').click();
|
|
|
|
|
// const page1 = await page1Promise;
|
|
|
|
|
const download = await downloadPromise;
|
|
|
|
|
expect(await download.failure()).toBeNull()
|
|
|
|
|
});
|