Skip to content

Commit c314474

Browse files
committed
Add support for more Chromium browsers
1 parent 4d0e168 commit c314474

File tree

14 files changed

+592
-7
lines changed

14 files changed

+592
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,10 @@ pytest test_coffee_cart.py --trace
652652
--edge # (Shortcut for "--browser=edge".)
653653
--firefox # (Shortcut for "--browser=firefox".)
654654
--safari # (Shortcut for "--browser=safari".)
655+
--opera # (Shortcut for "--browser=opera".)
656+
--brave # (Shortcut for "--browser=brave".)
657+
--comet # (Shortcut for "--browser=comet".)
658+
--atlas # (Shortcut for "--browser=atlas".)
655659
--settings-file=FILE # (Override default SeleniumBase settings.)
656660
--env=ENV # (Set the test env. Access with "self.env" in tests.)
657661
--account=STR # (Set account. Access with "self.account" in tests.)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ packages = [
4343
"seleniumbase.drivers",
4444
"seleniumbase.drivers.cft_drivers",
4545
"seleniumbase.drivers.chs_drivers",
46+
"seleniumbase.drivers.opera_drivers",
47+
"seleniumbase.drivers.brave_drivers",
48+
"seleniumbase.drivers.comet_drivers",
49+
"seleniumbase.drivers.atlas_drivers",
4650
"seleniumbase.extensions",
4751
"seleniumbase.fixtures",
4852
"seleniumbase.js_code",

seleniumbase/core/browser_launcher.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
2929
from seleniumbase.drivers import cft_drivers # chrome-for-testing
3030
from seleniumbase.drivers import chs_drivers # chrome-headless-shell
31+
from seleniumbase.drivers import opera_drivers # still uses chromedriver
32+
from seleniumbase.drivers import brave_drivers # still uses chromedriver
33+
from seleniumbase.drivers import comet_drivers # still uses chromedriver
34+
from seleniumbase.drivers import atlas_drivers # still uses chromedriver
3135
from seleniumbase import extensions # browser extensions storage folder
3236
from seleniumbase.config import settings
3337
from seleniumbase.core import detect_b_ver
@@ -44,6 +48,10 @@
4448
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
4549
DRIVER_DIR_CFT = os.path.dirname(os.path.realpath(cft_drivers.__file__))
4650
DRIVER_DIR_CHS = os.path.dirname(os.path.realpath(chs_drivers.__file__))
51+
DRIVER_DIR_OPERA = os.path.dirname(os.path.realpath(opera_drivers.__file__))
52+
DRIVER_DIR_BRAVE = os.path.dirname(os.path.realpath(brave_drivers.__file__))
53+
DRIVER_DIR_COMET = os.path.dirname(os.path.realpath(comet_drivers.__file__))
54+
DRIVER_DIR_ATLAS = os.path.dirname(os.path.realpath(atlas_drivers.__file__))
4755
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
4856
# (Changes to the System PATH with os.environ only last during the test run)
4957
if not os.environ["PATH"].startswith(DRIVER_DIR):
@@ -1218,8 +1226,8 @@ def uc_gui_click_x_y(driver, x, y, timeframe=0.25):
12181226
driver.cdp.minimize()
12191227
driver.cdp.set_window_rect(win_x, win_y, width, height)
12201228
if IS_WINDOWS:
1221-
x = x * width_ratio
1222-
y = y * width_ratio
1229+
x = x * (width_ratio + 0.03)
1230+
y = y * (width_ratio - 0.03)
12231231
_uc_gui_click_x_y(driver, x, y, timeframe=timeframe, uc_lock=False)
12241232
return
12251233
with suppress(Exception):
@@ -1260,7 +1268,7 @@ def _uc_gui_click_captcha(
12601268
ctype=None,
12611269
):
12621270
cdp_mode_on_at_start = __is_cdp_swap_needed(driver)
1263-
if cdp_mode_on_at_start and (not ctype or ctype == "cf_t"):
1271+
if cdp_mode_on_at_start:
12641272
return driver.cdp.gui_click_captcha()
12651273
_on_a_captcha_page = None
12661274
if ctype == "cf_t":
@@ -1952,6 +1960,15 @@ def get_valid_binary_names_for_browser(browser):
19521960
raise Exception("Invalid combination for OS browser binaries!")
19531961

19541962

1963+
def _special_binary_exists(location, name):
1964+
filename = str(location).split("/")[-1].split("\\")[-1]
1965+
return (
1966+
location
1967+
and str(name).lower() in filename.lower()
1968+
and os.path.exists(location)
1969+
)
1970+
1971+
19551972
def _repair_chromedriver(chrome_options, headless_options, mcv=None):
19561973
if mcv:
19571974
subprocess.check_call(
@@ -2960,6 +2977,14 @@ def get_driver(
29602977
and sb_config.binary_location == "chs"
29612978
):
29622979
driver_dir = DRIVER_DIR_CHS
2980+
if _special_binary_exists(binary_location, "opera"):
2981+
driver_dir = DRIVER_DIR_OPERA
2982+
if _special_binary_exists(binary_location, "brave"):
2983+
driver_dir = DRIVER_DIR_BRAVE
2984+
if _special_binary_exists(binary_location, "comet"):
2985+
driver_dir = DRIVER_DIR_COMET
2986+
if _special_binary_exists(binary_location, "atlas"):
2987+
driver_dir = DRIVER_DIR_ATLAS
29632988
if (
29642989
hasattr(sb_config, "settings")
29652990
and hasattr(sb_config.settings, "NEW_DRIVER_DIR")
@@ -3919,6 +3944,18 @@ def get_local_driver(
39193944
):
39203945
special_chrome = True
39213946
driver_dir = DRIVER_DIR_CHS
3947+
if _special_binary_exists(binary_location, "opera"):
3948+
special_chrome = True
3949+
driver_dir = DRIVER_DIR_OPERA
3950+
if _special_binary_exists(binary_location, "brave"):
3951+
special_chrome = True
3952+
driver_dir = DRIVER_DIR_BRAVE
3953+
if _special_binary_exists(binary_location, "comet"):
3954+
special_chrome = True
3955+
driver_dir = DRIVER_DIR_COMET
3956+
if _special_binary_exists(binary_location, "atlas"):
3957+
special_chrome = True
3958+
driver_dir = DRIVER_DIR_ATLAS
39223959
if (
39233960
hasattr(sb_config, "settings")
39243961
and hasattr(sb_config.settings, "NEW_DRIVER_DIR")
@@ -4756,6 +4793,27 @@ def get_local_driver(
47564793
)
47574794
return extend_driver(driver)
47584795
elif browser_name == constants.Browser.GOOGLE_CHROME:
4796+
set_chromium = None
4797+
if _special_binary_exists(binary_location, "opera"):
4798+
set_chromium = "opera"
4799+
local_chromedriver = DRIVER_DIR_OPERA + "/chromedriver"
4800+
if IS_WINDOWS:
4801+
local_chromedriver = DRIVER_DIR_OPERA + "/chromedriver.exe"
4802+
if _special_binary_exists(binary_location, "brave"):
4803+
set_chromium = "brave"
4804+
local_chromedriver = DRIVER_DIR_BRAVE + "/chromedriver"
4805+
if IS_WINDOWS:
4806+
local_chromedriver = DRIVER_DIR_BRAVE + "/chromedriver.exe"
4807+
if _special_binary_exists(binary_location, "comet"):
4808+
set_chromium = "comet"
4809+
local_chromedriver = DRIVER_DIR_COMET + "/chromedriver"
4810+
if IS_WINDOWS:
4811+
local_chromedriver = DRIVER_DIR_COMET + "/chromedriver.exe"
4812+
if _special_binary_exists(binary_location, "atlas"):
4813+
set_chromium = "atlas"
4814+
local_chromedriver = DRIVER_DIR_ATLAS + "/chromedriver"
4815+
if IS_WINDOWS:
4816+
local_chromedriver = DRIVER_DIR_ATLAS + "/chromedriver.exe"
47594817
try:
47604818
chrome_options = _set_chrome_options(
47614819
browser_name,
@@ -4877,6 +4935,12 @@ def get_local_driver(
48774935
major_chrome_version = None
48784936
if major_chrome_version:
48794937
use_version = major_chrome_version
4938+
if (
4939+
set_chromium == "opera"
4940+
and use_version.isnumeric()
4941+
and int(use_version) < 130
4942+
):
4943+
use_version = "130" # Special case
48804944
ch_driver_version = None
48814945
path_chromedriver = chromedriver_on_path()
48824946
if os.path.exists(local_chromedriver):
@@ -4894,7 +4958,7 @@ def get_local_driver(
48944958
ch_driver_version = output
48954959
if driver_version == "keep":
48964960
driver_version = ch_driver_version
4897-
elif path_chromedriver:
4961+
elif path_chromedriver and not set_chromium:
48984962
try:
48994963
make_driver_executable_if_not(path_chromedriver)
49004964
except Exception as e:

seleniumbase/drivers/atlas_drivers/__init__.py

Whitespace-only changes.

seleniumbase/drivers/brave_drivers/__init__.py

Whitespace-only changes.

seleniumbase/drivers/comet_drivers/__init__.py

Whitespace-only changes.

seleniumbase/drivers/opera_drivers/__init__.py

Whitespace-only changes.

seleniumbase/fixtures/constants.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ class ValidBrowsers:
387387
"ie",
388388
"safari",
389389
"remote",
390+
"opera",
391+
"brave",
392+
"comet",
393+
"atlas",
394+
]
395+
396+
397+
class ChromiumSubs:
398+
# Chromium browsers that still use chromedriver
399+
chromium_subs = [
400+
"opera",
401+
"brave",
402+
"comet",
403+
"atlas",
390404
]
391405

392406

@@ -430,8 +444,12 @@ class ValidBinaries:
430444
"Google Chrome Beta",
431445
"Google Chrome Dev",
432446
"Brave Browser",
447+
"Brave",
448+
"Opera Browser",
433449
"Opera",
450+
"Comet Browser",
434451
"Comet",
452+
"Atlas Browser",
435453
"Atlas",
436454
]
437455
valid_edge_binaries_on_macos = [

seleniumbase/plugins/driver_manager.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def Driver(
239239
from seleniumbase import config as sb_config
240240
from seleniumbase.config import settings
241241
from seleniumbase.core import browser_launcher
242+
from seleniumbase.core import detect_b_ver
242243
from seleniumbase.fixtures import constants
243244
from seleniumbase.fixtures import shared_utils
244245

@@ -271,10 +272,37 @@ def Driver(
271272
)
272273
elif existing_runner:
273274
sb_config._context_of_runner = True
275+
sb_config._browser_shortcut = None
276+
sb_config._cdp_browser = None
277+
sb_config._cdp_bin_loc = None
274278
browser_changes = 0
275279
browser_set = None
276280
browser_text = None
277281
browser_list = []
282+
# Check if binary-location in options
283+
bin_loc_in_options = False
284+
if (
285+
binary_location
286+
and len(str(binary_location)) > 5
287+
and os.path.exists(str(binary_location))
288+
):
289+
bin_loc_in_options = True
290+
else:
291+
for arg in sys_argv:
292+
if arg in ["--binary-location", "--binary_location", "--bl"]:
293+
bin_loc_in_options = True
294+
if (
295+
browser
296+
and browser in constants.ChromiumSubs.chromium_subs
297+
and not bin_loc_in_options
298+
):
299+
bin_loc = detect_b_ver.get_binary_location(browser)
300+
if bin_loc and os.path.exists(bin_loc):
301+
if browser in bin_loc.lower().split("/")[-1].split("\\")[-1]:
302+
sb_config._cdp_browser = browser
303+
sb_config._cdp_bin_loc = bin_loc
304+
binary_location = bin_loc
305+
bin_loc_in_options = True
278306
# As a shortcut, you can use "--edge" instead of "--browser=edge", etc,
279307
# but you can only specify one default browser for tests. (Default: chrome)
280308
if "--browser=chrome" in sys_argv or "--browser chrome" in sys_argv:
@@ -301,6 +329,46 @@ def Driver(
301329
browser_changes += 1
302330
browser_set = "remote"
303331
browser_list.append("--browser=remote")
332+
if "--browser=opera" in sys_argv or "--browser opera" in sys_argv:
333+
if not bin_loc_in_options:
334+
bin_loc = detect_b_ver.get_binary_location("opera")
335+
if os.path.exists(bin_loc):
336+
browser_changes += 1
337+
browser_set = "opera"
338+
sb_config._browser_shortcut = "opera"
339+
sb_config._cdp_browser = "opera"
340+
sb_config._cdp_bin_loc = bin_loc
341+
browser_list.append("--browser=opera")
342+
if "--browser=brave" in sys_argv or "--browser brave" in sys_argv:
343+
if not bin_loc_in_options:
344+
bin_loc = detect_b_ver.get_binary_location("brave")
345+
if os.path.exists(bin_loc):
346+
browser_changes += 1
347+
browser_set = "brave"
348+
sb_config._browser_shortcut = "brave"
349+
sb_config._cdp_browser = "brave"
350+
sb_config._cdp_bin_loc = bin_loc
351+
browser_list.append("--browser=brave")
352+
if "--browser=comet" in sys_argv or "--browser comet" in sys_argv:
353+
if not bin_loc_in_options:
354+
bin_loc = detect_b_ver.get_binary_location("comet")
355+
if os.path.exists(bin_loc):
356+
browser_changes += 1
357+
browser_set = "comet"
358+
sb_config._browser_shortcut = "comet"
359+
sb_config._cdp_browser = "comet"
360+
sb_config._cdp_bin_loc = bin_loc
361+
browser_list.append("--browser=comet")
362+
if "--browser=atlas" in sys_argv or "--browser atlas" in sys_argv:
363+
if not bin_loc_in_options:
364+
bin_loc = detect_b_ver.get_binary_location("atlas")
365+
if os.path.exists(bin_loc):
366+
browser_changes += 1
367+
browser_set = "atlas"
368+
sb_config._browser_shortcut = "atlas"
369+
sb_config._cdp_browser = "atlas"
370+
sb_config._cdp_bin_loc = bin_loc
371+
browser_list.append("--browser=atlas")
304372
browser_text = browser_set
305373
if "--chrome" in sys_argv and not browser_set == "chrome":
306374
browser_changes += 1
@@ -322,6 +390,46 @@ def Driver(
322390
browser_changes += 1
323391
browser_text = "safari"
324392
browser_list.append("--safari")
393+
if "--opera" in sys_argv and not browser_set == "opera":
394+
if not bin_loc_in_options:
395+
bin_loc = detect_b_ver.get_binary_location("opera")
396+
if os.path.exists(bin_loc):
397+
browser_changes += 1
398+
browser_text = "opera"
399+
sb_config._browser_shortcut = "opera"
400+
sb_config._cdp_browser = "opera"
401+
sb_config._cdp_bin_loc = bin_loc
402+
browser_list.append("--opera")
403+
if "--brave" in sys_argv and not browser_set == "brave":
404+
if not bin_loc_in_options:
405+
bin_loc = detect_b_ver.get_binary_location("brave")
406+
if os.path.exists(bin_loc):
407+
browser_changes += 1
408+
browser_text = "brave"
409+
sb_config._browser_shortcut = "brave"
410+
sb_config._cdp_browser = "brave"
411+
sb_config._cdp_bin_loc = bin_loc
412+
browser_list.append("--brave")
413+
if "--comet" in sys_argv and not browser_set == "comet":
414+
if not bin_loc_in_options:
415+
bin_loc = detect_b_ver.get_binary_location("comet")
416+
if os.path.exists(bin_loc):
417+
browser_changes += 1
418+
browser_text = "comet"
419+
sb_config._browser_shortcut = "comet"
420+
sb_config._cdp_browser = "comet"
421+
sb_config._cdp_bin_loc = bin_loc
422+
browser_list.append("--comet")
423+
if "--atlas" in sys_argv and not browser_set == "atlas":
424+
if not bin_loc_in_options:
425+
bin_loc = detect_b_ver.get_binary_location("atlas")
426+
if os.path.exists(bin_loc):
427+
browser_changes += 1
428+
browser_text = "atlas"
429+
sb_config._browser_shortcut = "atlas"
430+
sb_config._cdp_browser = "atlas"
431+
sb_config._cdp_bin_loc = bin_loc
432+
browser_list.append("--atlas")
325433
if browser_changes > 1:
326434
message = "\n\n TOO MANY browser types were entered!"
327435
message += "\n There were %s found:\n > %s" % (
@@ -345,6 +453,10 @@ def Driver(
345453
"Browser: {%s} is not a valid browser option. "
346454
"Valid options = {%s}" % (browser, valid_browsers)
347455
)
456+
if sb_config._browser_shortcut:
457+
browser = sb_config._browser_shortcut
458+
if browser in constants.ChromiumSubs.chromium_subs:
459+
browser = "chrome" # Still uses chromedriver
348460
if headless is None:
349461
if "--headless" in sys_argv:
350462
headless = True
@@ -534,6 +646,8 @@ def Driver(
534646
count += 1
535647
user_agent = agent
536648
found_bl = None
649+
if hasattr(sb_config, "_cdp_bin_loc") and sb_config._cdp_bin_loc:
650+
binary_location = sb_config._cdp_bin_loc
537651
if binary_location is None and "--binary-location" in arg_join:
538652
count = 0
539653
for arg in sys_argv:

0 commit comments

Comments
 (0)