test: intercept multipart request body (#14630)
This commit is contained in:
Родитель
c1a489ee4e
Коммит
7596379e63
|
@ -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'));
|
||||
});
|
Загрузка…
Ссылка в новой задаче