From 7596379e63ba898cbea5d078c326529f25cb1b83 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 7 Jun 2022 09:00:51 -0700 Subject: [PATCH] test: intercept multipart request body (#14630) --- tests/page/page-request-intercept.spec.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.ts index 76442d831d..4776765f3c 100644 --- a/tests/page/page-request-intercept.spec.ts +++ b/tests/page/page-request-intercept.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import type { Route } from 'playwright-core'; +import type { Route, Request } from 'playwright-core'; import { expect, test as base } from './pageTest'; import fs from 'fs'; import path from 'path'; @@ -174,3 +174,22 @@ it('should give access to the intercepted response body', async ({ page, server, await Promise.all([route.fulfill({ response }), evalPromise]); }); + +it('should intercept multipart/form-data request body', async ({ page, server, asset, browserName }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/14624' }); + it.fail(browserName !== 'firefox'); + await page.goto(server.PREFIX + '/input/fileupload.html'); + const filePath = path.relative(process.cwd(), asset('file-to-upload.txt')); + await page.locator('input[type=file]').setInputFiles(filePath); + const requestPromise = new Promise(async fulfill => { + await page.route('**/upload', route => { + fulfill(route.request()); + }); + }); + const [request] = await Promise.all([ + requestPromise, + page.click('input[type=submit]', { noWaitAfter: true }) + ]); + expect(request.method()).toBe('POST'); + expect(request.postData()).toContain(fs.readFileSync(filePath, 'utf8')); +}); \ No newline at end of file