MCPcopy Index your code
hub / github.com/microsoft/playwright-python / test_should_upload_large_file

Function test_should_upload_large_file

tests/async/test_input.py:318–361  ·  view source on GitHub ↗
(
    page: Page, server: Server, tmp_path: Path
)

Source from the content-addressed store, hash-verified

316
317
318async def test_should_upload_large_file(
319 page: Page, server: Server, tmp_path: Path
320) -> None:
321 await page.goto(server.PREFIX + "/input/fileupload.html")
322 large_file_path = tmp_path / "200MB.zip"
323 data = b"A" * 1024
324 with large_file_path.open("wb") as f:
325 for i in range(0, 200 * 1024 * 1024, len(data)):
326 f.write(data)
327 input = page.locator('input[type="file"]')
328 events = await input.evaluate_handle(
329 """
330 e => {
331 const events = [];
332 e.addEventListener('input', () => events.push('input'));
333 e.addEventListener('change', () => events.push('change'));
334 return events;
335 }
336 """
337 )
338
339 await input.set_input_files(large_file_path)
340 assert await input.evaluate("e => e.files[0].name") == "200MB.zip"
341 assert await events.evaluate("e => e") == ["input", "change"]
342
343 [request, _] = await asyncio.gather(
344 server.wait_for_request("/upload"),
345 page.click("input[type=submit]"),
346 )
347
348 contents = request.args[b"file1"][0]
349 assert len(contents) == 200 * 1024 * 1024
350 assert contents[:1024] == data
351 # flake8: noqa: E203
352 assert contents[len(contents) - 1024 :] == data
353 assert request.post_body
354 match = re.search(
355 rb'^.*Content-Disposition: form-data; name="(?P<name>.*)"; filename="(?P<filename>.*)".*$',
356 request.post_body,
357 re.MULTILINE,
358 )
359 assert match
360 assert match.group("name") == b"file1"
361 assert match.group("filename") == b"200MB.zip"
362
363
364async def test_set_input_files_should_preserve_last_modified_timestamp(

Callers

nothing calls this directly

Calls 8

wait_for_requestMethod · 0.80
gotoMethod · 0.45
locatorMethod · 0.45
evaluate_handleMethod · 0.45
set_input_filesMethod · 0.45
evaluateMethod · 0.45
clickMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected