Skip to content

Commit 732639b

Browse files
committed
cherry-pick(3014): chore: throw FileNotFoundError for nonexistant files (#3014)
1 parent a2e39af commit 732639b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

playwright/_impl/_set_input_files_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import base64
1515
import collections.abc
1616
import os
17+
import stat
1718
from pathlib import Path
1819
from typing import (
1920
TYPE_CHECKING,
@@ -144,7 +145,8 @@ def resolve_paths_and_directory_for_input_files(
144145
local_paths: Optional[List[str]] = None
145146
local_directory: Optional[str] = None
146147
for item in items:
147-
if os.path.isdir(item):
148+
item_stat = os.stat(item) # Raises FileNotFoundError if doesn't exist
149+
if stat.S_ISDIR(item_stat.st_mode):
148150
if local_directory:
149151
raise Error("Multiple directories are not supported")
150152
local_directory = str(Path(item).resolve())

tests/sync/test_locators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ def test_locators_should_upload_a_file(page: Page, server: Server) -> None:
327327
)
328328

329329

330+
def test_locators_upload_nonexistant_file(page: Page, server: Server) -> None:
331+
page.goto(server.PREFIX + "/input/fileupload.html")
332+
with pytest.raises(FileNotFoundError):
333+
page.locator("input[type=file]").set_input_files("nonexistant.html")
334+
335+
330336
def test_locators_should_press(page: Page) -> None:
331337
page.set_content("<input type='text' />")
332338
page.locator("input").press("h")

0 commit comments

Comments
 (0)