test: intercept multipart request body (#14630)

This commit is contained in:
Yury Semikhatsky 2022-06-07 09:00:51 -07:00 коммит произвёл GitHub
Родитель c1a489ee4e
Коммит 7596379e63
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -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'));
});