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

Function test_should_upload_a_folder

tests/async/test_input.py:414–461  ·  view source on GitHub ↗
(
    page: Page,
    server: Server,
    tmp_path: Path,
    browser_name: str,
    browser_version: str,
    headless: bool,
)

Source from the content-addressed store, hash-verified

412
413
414async def test_should_upload_a_folder(
415 page: Page,
416 server: Server,
417 tmp_path: Path,
418 browser_name: str,
419 browser_version: str,
420 headless: bool,
421) -> None:
422 await page.goto(server.PREFIX + "/input/folderupload.html")
423 input = await page.query_selector("input")
424 assert input
425 dir = tmp_path / "file-upload-test"
426 dir.mkdir()
427 (dir / "file1.txt").write_text("file1 content")
428 (dir / "file2").write_text("file2 content")
429 (dir / "sub-dir").mkdir()
430 (dir / "sub-dir" / "really.txt").write_text("sub-dir file content")
431 await input.set_input_files(dir)
432 assert set(
433 await input.evaluate("e => [...e.files].map(f => f.webkitRelativePath)")
434 ) == set(
435 [
436 "file-upload-test/file1.txt",
437 "file-upload-test/file2",
438 # https://issues.chromium.org/issues/345393164
439 *(
440 []
441 if browser_name == "chromium"
442 and headless
443 and chromium_version_less_than(browser_version, "127.0.6533.0")
444 else ["file-upload-test/sub-dir/really.txt"]
445 ),
446 ]
447 )
448 webkit_relative_paths = await input.evaluate(
449 "e => [...e.files].map(f => f.webkitRelativePath)"
450 )
451 for i, webkit_relative_path in enumerate(webkit_relative_paths):
452 content = await input.evaluate(
453 """(e, i) => {
454 const reader = new FileReader();
455 const promise = new Promise(fulfill => reader.onload = fulfill);
456 reader.readAsText(e.files[i]);
457 return promise.then(() => reader.result);
458 }""",
459 i,
460 )
461 assert content == (dir / ".." / webkit_relative_path).read_text()
462
463
464async def test_should_upload_a_folder_and_throw_for_multiple_directories(

Callers

nothing calls this directly

Calls 5

gotoMethod · 0.45
query_selectorMethod · 0.45
set_input_filesMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected