From e6a5ec875e7de3510fb843a34b981c4081c96fda Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 14 Jul 2022 00:18:28 -0400 Subject: [PATCH] Improve error-handling for Firefox tests --- seleniumbase/core/browser_launcher.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/seleniumbase/core/browser_launcher.py b/seleniumbase/core/browser_launcher.py index 3e94d4243b7..ce3deef8819 100755 --- a/seleniumbase/core/browser_launcher.py +++ b/seleniumbase/core/browser_launcher.py @@ -1511,7 +1511,11 @@ def get_local_driver( options=firefox_options, ) except Exception as e: - if "Process unexpectedly closed" in e.msg: + if ( + "Process unexpectedly closed" in e.msg + or "Failed to read marionette port" in e.msg + or "A connection attempt failed" in e.msg + ): # Firefox probably just auto-updated itself. # Trying again right after that often works. return webdriver.Firefox( @@ -1529,9 +1533,24 @@ def get_local_driver( else: if selenium4: service = FirefoxService(log_path=os.path.devnull) - return webdriver.Firefox( - service=service, options=firefox_options - ) + try: + return webdriver.Firefox( + service=service, options=firefox_options + ) + except Exception as e: + if ( + "Process unexpectedly closed" in e.msg + or "Failed to read marionette port" in e.msg + or "A connection attempt failed" in e.msg + ): + # Firefox probably just auto-updated itself. + # Trying again right after that often works. + return webdriver.Firefox( + service=service, + options=firefox_options, + ) + else: + raise Exception(e.msg) # Not an obvious fix. else: return webdriver.Firefox( service_log_path=os.path.devnull,