Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: intercept multipart request body (#14630)
Yury Semikhatsky7596379e63ba
diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.tsindex 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<Request>(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