@@ -847,6 +847,11 @@ def _set_firefox_options(
847
847
)
848
848
if headless and not IS_LINUX :
849
849
options .add_argument ("--headless" )
850
+ elif headless and IS_LINUX :
851
+ # This assumes Xvfb is running, which prevents many Linux issues.
852
+ # If not, we'll fix this later during the error-handling process.
853
+ # To override this feature: ``pytest --firefox-arg="-headless"``.
854
+ pass
850
855
if locale_code :
851
856
options .set_preference ("intl.accept_languages" , locale_code )
852
857
options .set_preference ("browser.shell.checkDefaultBrowser" , False )
@@ -1972,10 +1977,18 @@ def get_local_driver(
1972
1977
or "A connection attempt failed" in e .msg
1973
1978
)
1974
1979
):
1975
- # Firefox probably just auto-updated itself,
1976
- # which causes intermittent issues to occur.
1977
- # Trying again right after that often works.
1978
1980
time .sleep (0.1 )
1981
+ if (
1982
+ IS_LINUX
1983
+ and headless
1984
+ and (
1985
+ "unexpected" in str (e )
1986
+ or (
1987
+ hasattr (e , "msg" ) and "unexpected" in e .msg
1988
+ )
1989
+ )
1990
+ ):
1991
+ firefox_options .add_argument ("-headless" )
1979
1992
return webdriver .Firefox (
1980
1993
service = service ,
1981
1994
options = firefox_options ,
@@ -1993,7 +2006,8 @@ def get_local_driver(
1993
2006
service = FirefoxService (log_path = os .devnull )
1994
2007
try :
1995
2008
return webdriver .Firefox (
1996
- service = service , options = firefox_options
2009
+ service = service ,
2010
+ options = firefox_options ,
1997
2011
)
1998
2012
except BaseException as e :
1999
2013
if (
@@ -2008,10 +2022,18 @@ def get_local_driver(
2008
2022
or "A connection attempt failed" in e .msg
2009
2023
)
2010
2024
):
2011
- # Firefox probably just auto-updated itself,
2012
- # which causes intermittent issues to occur.
2013
- # Trying again right after that often works.
2014
2025
time .sleep (0.1 )
2026
+ if (
2027
+ IS_LINUX
2028
+ and headless
2029
+ and (
2030
+ "unexpected" in str (e )
2031
+ or (
2032
+ hasattr (e , "msg" ) and "unexpected" in e .msg
2033
+ )
2034
+ )
2035
+ ):
2036
+ firefox_options .add_argument ("-headless" )
2015
2037
return webdriver .Firefox (
2016
2038
service = service ,
2017
2039
options = firefox_options ,
0 commit comments