Skip to content

Commit 5d8be67

Browse files
committed
More Chromium updates
1 parent 7d0921b commit 5d8be67

File tree

7 files changed

+95
-13
lines changed

7 files changed

+95
-13
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,19 @@ def uc_open_with_tab(driver, url):
551551

552552
def uc_open_with_reconnect(driver, url, reconnect_time=None):
553553
"""Open a url, disconnect chromedriver, wait, and reconnect."""
554+
if (
555+
hasattr(sb_config, "_cdp_browser")
556+
and sb_config._cdp_browser in ["comet", "opera", "atlas"]
557+
):
558+
if not __is_cdp_swap_needed(driver):
559+
if not driver.current_url.startswith(
560+
("about", "data", "chrome")
561+
):
562+
driver.get("about:blank")
563+
uc_activate_cdp_mode(driver, url)
564+
else:
565+
driver.cdp.open(url)
566+
return
554567
url = shared_utils.fix_url_as_needed(url)
555568
if __is_cdp_swap_needed(driver):
556569
driver.cdp.get(url)
@@ -2979,12 +2992,16 @@ def get_driver(
29792992
driver_dir = DRIVER_DIR_CHS
29802993
if _special_binary_exists(binary_location, "opera"):
29812994
driver_dir = DRIVER_DIR_OPERA
2995+
sb_config._cdp_browser = "opera"
29822996
if _special_binary_exists(binary_location, "brave"):
29832997
driver_dir = DRIVER_DIR_BRAVE
2998+
sb_config._cdp_browser = "brave"
29842999
if _special_binary_exists(binary_location, "comet"):
29853000
driver_dir = DRIVER_DIR_COMET
3001+
sb_config._cdp_browser = "comet"
29863002
if _special_binary_exists(binary_location, "atlas"):
29873003
driver_dir = DRIVER_DIR_ATLAS
3004+
sb_config._cdp_browser = "atlas"
29883005
if (
29893006
hasattr(sb_config, "settings")
29903007
and hasattr(sb_config.settings, "NEW_DRIVER_DIR")
@@ -2997,6 +3014,8 @@ def get_driver(
29973014
browser_name = browser
29983015
else:
29993016
browser_name = "chrome" # The default if not specified
3017+
if browser_name in constants.ChromiumSubs.chromium_subs:
3018+
browser_name = "chrome"
30003019
browser_name = browser_name.lower()
30013020
if headless2 and browser_name == constants.Browser.FIREFOX:
30023021
headless2 = False # Only for Chromium

seleniumbase/core/detect_b_ver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def opera_on_windows_path(browser_type=None):
278278
),
279279
):
280280
for subitem in (
281+
"Programs/Opera",
281282
"Opera",
282283
"Opera/Application",
283284
):
@@ -336,6 +337,7 @@ def comet_on_windows_path(browser_type=None):
336337
):
337338
for subitem in (
338339
"Comet/Application",
340+
"Programs/Comet",
339341
):
340342
try:
341343
candidates.append(os.sep.join((item, subitem, "Comet.exe")))
@@ -364,6 +366,7 @@ def atlas_on_windows_path(browser_type=None):
364366
):
365367
for subitem in (
366368
"Atlas/Application",
369+
"Programs/Atlas",
367370
):
368371
try:
369372
candidates.append(os.sep.join((item, subitem, "Atlas.exe")))

seleniumbase/fixtures/base_case.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,7 +4354,7 @@ def get_new_driver(
43544354
elif self.browser == "firefox":
43554355
try:
43564356
if self.maximize_option:
4357-
self.driver.maximize_window()
4357+
self.maximize_window()
43584358
self.wait_for_ready_state_complete()
43594359
else:
43604360
with suppress(Exception):
@@ -4364,7 +4364,7 @@ def get_new_driver(
43644364
elif self.browser == "safari":
43654365
if self.maximize_option:
43664366
try:
4367-
self.driver.maximize_window()
4367+
self.maximize_window()
43684368
self.wait_for_ready_state_complete()
43694369
except Exception:
43704370
pass # Keep existing browser resolution
@@ -11408,7 +11408,13 @@ def __get_new_timeout(self, timeout):
1140811408

1140911409
def __is_cdp_swap_needed(self):
1141011410
"""If the driver is disconnected, use a CDP method when available."""
11411-
return shared_utils.is_cdp_swap_needed(self.driver)
11411+
cdp_swap_needed = shared_utils.is_cdp_swap_needed(self.driver)
11412+
if cdp_swap_needed:
11413+
if not self.cdp:
11414+
self.cdp = self.driver.cdp
11415+
return True
11416+
else:
11417+
return False
1141211418

1141311419
############
1141411420

@@ -14001,7 +14007,7 @@ def __click_with_offset(
1400114007
)
1400214008
raise Exception(message)
1400314009
except InvalidArgumentException:
14004-
if not self.browser == "chrome":
14010+
if not self.is_chromium():
1400514011
raise
1400614012
chrome_version = self.driver.capabilities["browserVersion"]
1400714013
major_chrome_version = chrome_version.split(".")[0]
@@ -14616,7 +14622,7 @@ def __get_shadow_element(
1461614622
try:
1461714623
shadow_root = element.shadow_root
1461814624
except Exception:
14619-
if self.browser == "chrome":
14625+
if self.is_chromium():
1462014626
chrome_dict = self.driver.capabilities["chrome"]
1462114627
chrome_dr_version = chrome_dict["chromedriverVersion"]
1462214628
chromedriver_version = chrome_dr_version.split(" ")[0]

seleniumbase/plugins/driver_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,6 @@ def Driver(
455455
)
456456
if sb_config._browser_shortcut:
457457
browser = sb_config._browser_shortcut
458-
if browser in constants.ChromiumSubs.chromium_subs:
459-
browser = "chrome" # Still uses chromedriver
460458
if headless is None:
461459
if "--headless" in sys_argv:
462460
headless = True
@@ -953,6 +951,10 @@ def Driver(
953951
driver_version = None
954952
break
955953
count += 1
954+
if browser in constants.ChromiumSubs.chromium_subs:
955+
if not binary_location:
956+
browser = "chrome" # Still uses chromedriver
957+
sb_config._browser_shortcut = browser
956958
browser_name = browser
957959

958960
# Launch a web browser

seleniumbase/plugins/pytest_plugin.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,8 +1676,23 @@ def pytest_configure(config):
16761676
sb_config.browser = config.getoption("browser")
16771677
if sb_config._browser_shortcut:
16781678
sb_config.browser = sb_config._browser_shortcut
1679-
if sb_config.browser in constants.ChromiumSubs.chromium_subs:
1680-
sb_config.browser = "chrome" # Still uses chromedriver
1679+
elif sys_argv == ["-c"]: # Multithreading messes with args
1680+
if config.getoption("use_opera"):
1681+
bin_loc = detect_b_ver.get_binary_location("opera")
1682+
if bin_loc and os.path.exists(bin_loc):
1683+
sb_config.browser = "opera"
1684+
elif config.getoption("use_brave"):
1685+
bin_loc = detect_b_ver.get_binary_location("brave")
1686+
if bin_loc and os.path.exists(bin_loc):
1687+
sb_config.browser = "brave"
1688+
elif config.getoption("use_comet"):
1689+
bin_loc = detect_b_ver.get_binary_location("comet")
1690+
if bin_loc and os.path.exists(bin_loc):
1691+
sb_config.browser = "comet"
1692+
elif config.getoption("use_atlas"):
1693+
bin_loc = detect_b_ver.get_binary_location("atlas")
1694+
if bin_loc and os.path.exists(bin_loc):
1695+
sb_config.browser = "atlas"
16811696
sb_config.account = config.getoption("account")
16821697
sb_config.data = config.getoption("data")
16831698
sb_config.var1 = config.getoption("var1")
@@ -1714,6 +1729,35 @@ def pytest_configure(config):
17141729
sb_config.binary_location = config.getoption("binary_location")
17151730
if hasattr(sb_config, "_cdp_bin_loc") and sb_config._cdp_bin_loc:
17161731
sb_config.binary_location = sb_config._cdp_bin_loc
1732+
elif not sb_config.binary_location:
1733+
if (
1734+
config.getoption("use_opera")
1735+
or sb_config._browser_shortcut == "opera"
1736+
):
1737+
bin_loc = detect_b_ver.get_binary_location("opera")
1738+
if bin_loc and os.path.exists(bin_loc):
1739+
sb_config.binary_location = bin_loc
1740+
elif (
1741+
config.getoption("use_brave")
1742+
or sb_config._browser_shortcut == "brave"
1743+
):
1744+
bin_loc = detect_b_ver.get_binary_location("brave")
1745+
if bin_loc and os.path.exists(bin_loc):
1746+
sb_config.binary_location = bin_loc
1747+
elif (
1748+
config.getoption("use_comet")
1749+
or sb_config._browser_shortcut == "comet"
1750+
):
1751+
bin_loc = detect_b_ver.get_binary_location("comet")
1752+
if bin_loc and os.path.exists(bin_loc):
1753+
sb_config.binary_location = bin_loc
1754+
elif (
1755+
config.getoption("use_atlas")
1756+
or sb_config._browser_shortcut == "atlas"
1757+
):
1758+
bin_loc = detect_b_ver.get_binary_location("atlas")
1759+
if bin_loc and os.path.exists(bin_loc):
1760+
sb_config.binary_location = bin_loc
17171761
if config.getoption("use_cft") and not sb_config.binary_location:
17181762
sb_config.binary_location = "cft"
17191763
elif config.getoption("use_chs") and not sb_config.binary_location:
@@ -1726,6 +1770,10 @@ def pytest_configure(config):
17261770
sb_config.headless = True
17271771
sb_config.headless1 = False
17281772
sb_config.headless2 = False
1773+
if sb_config.browser in constants.ChromiumSubs.chromium_subs:
1774+
if not sb_config.binary_location:
1775+
sb_config.browser = "chrome" # Still uses chromedriver
1776+
sb_config._browser_shortcut = sb_config.browser
17291777
sb_config.driver_version = config.getoption("driver_version")
17301778
sb_config.page_load_strategy = config.getoption("page_load_strategy")
17311779
sb_config.with_testing_base = config.getoption("with_testing_base")

seleniumbase/plugins/sb_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,6 @@ def SB(
11321132
sb_config.browser = browser
11331133
if sb_config._browser_shortcut:
11341134
sb_config.browser = sb_config._browser_shortcut
1135-
if sb_config.browser in constants.ChromiumSubs.chromium_subs:
1136-
sb_config.browser = "chrome" # Still uses chromedriver
11371135
if not hasattr(sb_config, "is_behave"):
11381136
sb_config.is_behave = False
11391137
if not hasattr(sb_config, "is_pytest"):
@@ -1242,6 +1240,10 @@ def SB(
12421240
sb_config.interval = interval
12431241
sb_config.cap_file = cap_file
12441242
sb_config.cap_string = cap_string
1243+
if sb_config.browser in constants.ChromiumSubs.chromium_subs:
1244+
if not sb_config.binary_location:
1245+
sb_config.browser = "chrome" # Still uses chromedriver
1246+
sb_config._browser_shortcut = sb_config.browser
12451247

12461248
sb = BaseCase()
12471249
sb.with_testing_base = sb_config.with_testing_base

seleniumbase/plugins/selenium_plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,6 @@ def beforeTest(self, test):
13021302
if sb_config._browser_shortcut:
13031303
self.options.browser = sb_config._browser_shortcut
13041304
test.test.browser = sb_config._browser_shortcut
1305-
if test.test.browser in constants.ChromiumSubs.chromium_subs:
1306-
test.test.browser = "chrome" # Still uses chromedriver
13071305
test.test.cap_file = self.options.cap_file
13081306
test.test.cap_string = self.options.cap_string
13091307
test.test.headless = self.options.headless
@@ -1355,6 +1353,10 @@ def beforeTest(self, test):
13551353
test.test.headless = True
13561354
test.test.headless1 = False
13571355
test.test.headless2 = False
1356+
if test.test.browser in constants.ChromiumSubs.chromium_subs:
1357+
if not sb_config.binary_location:
1358+
test.test.browser = "chrome" # Still uses chromedriver
1359+
sb_config._browser_shortcut = test.test.browser
13581360
test.test.driver_version = self.options.driver_version
13591361
test.test.page_load_strategy = self.options.page_load_strategy
13601362
test.test.chromium_arg = self.options.chromium_arg

0 commit comments

Comments
 (0)