Skip to content

Commit 1db866f

Browse files
committed
Optimize driver settings
1 parent 07703ac commit 1db866f

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,13 +2702,16 @@ def get_local_driver(
27022702
)
27032703
return driver
27042704
elif browser_name == constants.Browser.SAFARI:
2705-
from selenium.webdriver.safari.options import Options as SafariOptions
2706-
27072705
arg_join = " ".join(sys.argv)
27082706
if ("-n" in sys.argv) or (" -n=" in arg_join) or (arg_join == "-c"):
27092707
# Skip if multithreaded
27102708
raise Exception("Can't run Safari tests in multithreaded mode!")
27112709
warnings.simplefilter("ignore", category=DeprecationWarning)
2710+
if not selenium4_or_newer:
2711+
return webdriver.safari.webdriver.WebDriver()
2712+
2713+
from selenium.webdriver.safari.options import Options as SafariOptions
2714+
27122715
service = SafariService(quiet=False)
27132716
options = SafariOptions()
27142717
if (
@@ -3270,7 +3273,10 @@ def get_local_driver(
32703273
elif "Missing or invalid capabilities" in e.msg:
32713274
if selenium4_or_newer:
32723275
chrome_options.add_experimental_option("w3c", True)
3273-
service = ChromeService(log_output=os.devnull)
3276+
service = ChromeService(
3277+
log_output=os.devnull,
3278+
service_args=service_args,
3279+
)
32743280
with warnings.catch_warnings():
32753281
warnings.simplefilter(
32763282
"ignore", category=DeprecationWarning
@@ -3369,6 +3375,7 @@ def get_local_driver(
33693375
if selenium4_or_newer:
33703376
service = ChromeService(
33713377
executable_path=LOCAL_CHROMEDRIVER,
3378+
log_output=os.devnull,
33723379
service_args=["--disable-build-check"],
33733380
)
33743381
driver = webdriver.Chrome(
@@ -3384,6 +3391,7 @@ def get_local_driver(
33843391
else:
33853392
if selenium4_or_newer:
33863393
service = ChromeService(
3394+
log_output=os.devnull,
33873395
service_args=["--disable-build-check"],
33883396
)
33893397
driver = webdriver.Chrome(
@@ -3420,7 +3428,10 @@ def get_local_driver(
34203428
elif "Missing or invalid capabilities" in e.msg:
34213429
if selenium4_or_newer:
34223430
chrome_options.add_experimental_option("w3c", True)
3423-
service = ChromeService(log_output=os.devnull)
3431+
service = ChromeService(
3432+
log_output=os.devnull,
3433+
service_args=["--disable-build-check"],
3434+
)
34243435
with warnings.catch_warnings():
34253436
warnings.simplefilter(
34263437
"ignore", category=DeprecationWarning
@@ -3467,6 +3478,7 @@ def get_local_driver(
34673478
try:
34683479
if selenium4_or_newer:
34693480
service = ChromeService(
3481+
log_output=os.devnull,
34703482
service_args=["--disable-build-check"],
34713483
)
34723484
return webdriver.Chrome(
@@ -3488,11 +3500,20 @@ def get_local_driver(
34883500
)
34893501
if "--headless" in chrome_options.arguments:
34903502
chrome_options.arguments.remove("--headless")
3491-
return webdriver.Chrome(options=chrome_options)
3503+
service = ChromeService(
3504+
log_output=os.devnull,
3505+
service_args=["--disable-build-check"]
3506+
)
3507+
return webdriver.Chrome(
3508+
service=service, options=chrome_options
3509+
)
34923510
except Exception:
34933511
try:
34943512
# Try again if Chrome didn't launch
3495-
return webdriver.Chrome(options=chrome_options)
3513+
service = ChromeService(service_args=["--disable-build-check"])
3514+
return webdriver.Chrome(
3515+
service=service, options=chrome_options
3516+
)
34963517
except Exception:
34973518
pass
34983519
if headless:
@@ -3505,7 +3526,11 @@ def get_local_driver(
35053526
"\nWarning: Could not make chromedriver"
35063527
" executable: %s" % e
35073528
)
3508-
return webdriver.Chrome()
3529+
service = ChromeService(
3530+
log_output=os.devnull,
3531+
service_args=["--disable-build-check"]
3532+
)
3533+
return webdriver.Chrome(service=service)
35093534
else:
35103535
raise Exception(
35113536
"%s is not a valid browser option for this system!" % browser_name

0 commit comments

Comments
 (0)