Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: repro for spaces in filename for input (#17452)

Ross Wollmanaf5e06fbfdb0
diff --git a/tests/assets/file to upload.txt b/tests/assets/file to upload.txt
new file mode 100644
index 0000000000..b4ad118489
--- /dev/null
+++ b/tests/assets/file to upload.txt
@@ -0,0 +1 @@
+contents of the file
\ No newline at end of file
diff --git a/tests/page/page-set-input-files.spec.ts b/tests/page/page-set-input-files.spec.ts
index d987bae577..14ea76fff4 100644
--- a/tests/page/page-set-input-files.spec.ts
+++ b/tests/page/page-set-input-files.spec.ts
@@ -135,6 +135,22 @@ it('should upload large file with relative path', async ({ page, server, browser
await Promise.all([uploadFile, file1.filepath].map(fs.promises.unlink));
});
+it('should upload the file with spaces in name', async ({ page, server, asset }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17451' });
+ await page.goto(server.PREFIX + '/input/fileupload.html');
+ const filePath = path.relative(process.cwd(), asset('file to upload.txt'));
+ const input = await page.$('input');
+ await input.setInputFiles(filePath);
+ expect(await page.evaluate(e => e.files[0].name, input)).toBe('file to upload.txt');
+ expect(await page.evaluate(e => {
+ const reader = new FileReader();
+ const promise = new Promise(fulfill => reader.onload = fulfill);
+ reader.readAsText(e.files[0]);
+ return promise.then(() => reader.result);
+ }, input)).toBe('contents of the file');
+});
+
+
it('should work @smoke', async ({ page, asset }) => {
await page.setContent(`<input type=file>`);
await page.setInputFiles('input', asset('file-to-upload.txt'));