Skip to content

Commit 1de579a

Browse files
authored
Merge branch 'trunk' into refactor
2 parents aede167 + 0e1ac19 commit 1de579a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

py/selenium/webdriver/remote/websocket_connection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from websocket import WebSocketApp # type: ignore
2424

25+
from selenium.common import WebDriverException
26+
2527
logger = logging.getLogger(__name__)
2628

2729

@@ -65,7 +67,12 @@ def execute(self, command):
6567
response = self._messages.pop(current_id)
6668

6769
if "error" in response:
68-
raise Exception(response["error"])
70+
error = response["error"]
71+
if "message" in response:
72+
error_msg = f"{error}: {response['message']}"
73+
raise WebDriverException(error_msg)
74+
else:
75+
raise WebDriverException(error)
6976
else:
7077
result = response["result"]
7178
return self._deserialize_result(result, command)
@@ -97,7 +104,7 @@ def _serialize_command(self, command):
97104
def _deserialize_result(self, result, command):
98105
try:
99106
_ = command.send(result)
100-
raise Exception("The command's generator function did not exit when expected!")
107+
raise WebDriverException("The command's generator function did not exit when expected!")
101108
except StopIteration as exit:
102109
return exit.value
103110

py/test/selenium/webdriver/remote/remote_downloads_tests.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ def test_get_downloadable_files(driver, pages):
3535
def test_download_file(driver, pages):
3636
_browser_downloads(driver, pages)
3737

38-
file_name = driver.get_downloadable_files()[0]
38+
# Get a list of downloadable files and find the txt file
39+
downloadable_files = driver.get_downloadable_files()
40+
text_file_name = next((file for file in downloadable_files if file.endswith(".txt")), None)
41+
assert text_file_name is not None, "Could not find a .txt file in downloadable files"
42+
3943
with tempfile.TemporaryDirectory() as target_directory:
40-
driver.download_file(file_name, target_directory)
44+
driver.download_file(text_file_name, target_directory)
4145

42-
target_file = os.path.join(target_directory, file_name)
46+
target_file = os.path.join(target_directory, text_file_name)
4347
with open(target_file, "r") as file:
4448
assert "Hello, World!" in file.read()
4549

0 commit comments

Comments
 (0)