playwright/examples/mock-filesystem/tests/file-reader.spec.js
2022-02-28 16:16:05 -08:00

25 lines
736 B
JavaScript

// @ts-check
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({page}) => {
await page.addInitScript(() => {
class FileSystemFileHandleMock {
constructor(file) {
this._file = file;
}
async getFile() {
return this._file;
}
}
window.showOpenFilePicker = async () => [new FileSystemFileHandleMock(new File(['Test content.'], "foo.txt"))];
});
});
test('show file picker with mock class', async ({ page }) => {
await page.goto('/file-picker.html');
await page.locator('button', { hasText: 'Open File' }).click();
// Check that the content of the mock file has been loaded.
await expect(page.locator('textarea')).toHaveValue('Test content.');
});