mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.15k stars 1.52k forks source link

UnexpectedAlertPresentException exc.msg does not contain the prompt message #2204

Open justinearl opened 5 days ago

justinearl commented 5 days ago

System

Description

The exception raised in geckodriver does not contain the prompt message anymore. In selenium UnexpectedAlertPresentException we do not have any info anymore what was the content of the automatically dismissed prompt

Current message

"message":"Unexpected alert dialog detected. Performed handler \"dismiss\""

Previous message

"message":"Dismissed user prompt dialog: This is a triggered alert!"

Is this the expected behavior now for geckodriver? For chrome the prompt message is still passed to the exception.

Testcase

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import UnexpectedAlertPresentException

firefox_options = Options()
# firefox_options.unhandled_prompt_behavior = "ignore"
firefox_options.log.level = "trace"
service = Service(executable_path=geckodriver_path, log_output="trace.log")
driver = webdriver.Firefox(service=service, options=firefox_options)

try:
    driver.get("data:text/html,<html><body></body></html>")
    driver.execute_script("alert('This is a triggered alert!');")
    assert driver.switch_to.alert.text
    driver.title  # Trigger unexpected alert
    assert False, "No exception"
except UnexpectedAlertPresentException as e:
    print(f"Exception: {e}")
    print(e.msg)
finally:
    driver.quit()

Stacktrace

Alert Text: None
Message: Unexpected alert dialog detected. Performed handler "dismiss"
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
UnexpectedAlertOpenError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:800:5
GeckoDriver.prototype._handleUserPrompts@chrome://remote/content/marionette/driver.sys.mjs:2962:11

Trace-level log

Attached file trace.log

1728528535324   webdriver::server   DEBUG   <- 500 Internal Server Error {"value":{"error":"unexpected alert open","message":"Unexpected alert dialog detected. Performed ... Errors.sys.mjs:800:5\nGeckoDriver.prototype._handleUserPrompts@chrome://remote/content/marionette/driver.sys.mjs:2962:11\n"}}

Old Trace log from Firefox 125.0.1 trace.log

1728527680840   webdriver::server   DEBUG   <- 500 Internal Server Error {"value":{"error":"unexpected alert open","message":"Dismissed user prompt dialog: This is a tri ... Errors.sys.mjs:800:5\nGeckoDriver.prototype._handleUserPrompts@chrome://remote/content/marionette/driver.sys.mjs:2835:13\n"}}

-->

juliandescottes commented 23 hours ago

The error message changed in https://bugzilla.mozilla.org/show_bug.cgi?id=1884650

I just filed https://bugzilla.mozilla.org/show_bug.cgi?id=1924469 to discuss about adding the message again