@@ -61,6 +61,12 @@ def test_anything(self):
6161from seleniumbase import config as sb_config
6262from seleniumbase.__version__ import __version__
6363from seleniumbase.common import decorators
64+ from seleniumbase.common.exceptions import (
65+ NotUsingChromeException,
66+ NotUsingChromiumException,
67+ OutOfScopeException,
68+ VisualException,
69+ )
6470from seleniumbase.config import settings
6571from seleniumbase.core import download_helper
6672from seleniumbase.core import log_helper
@@ -6493,6 +6499,12 @@ def get_browser_downloads_folder(self):
64936499 and self.headless
64946500 ):
64956501 return os.path.join(os.path.expanduser("~"), "downloads")
6502+ elif (
6503+ self.driver.capabilities["browserName"].lower() == "chrome"
6504+ and int(self.get_chromedriver_version().split(".")[0]) >= 110
6505+ and self.headless
6506+ ):
6507+ return os.path.abspath(".")
64966508 else:
64976509 return download_helper.get_downloads_folder()
64986510 return os.path.join(os.path.expanduser("~"), "downloads")
@@ -7092,17 +7104,27 @@ def __fail_if_not_using_chrome(self, method):
70927104 if browser_name.lower() == "chrome":
70937105 chrome = True
70947106 if not chrome:
7095- from seleniumbase.common.exceptions import NotUsingChromeException
7096-
70977107 message = (
7098- 'Error: "%s" should only be called '
7099- 'by tests running with self. browser == " chrome"! '
7108+ 'Error: "%s" should only be called by tests '
7109+ 'running with "-- browser=chrome" / "-- chrome"! '
71007110 'You should add an "if" statement to your code before calling '
71017111 "this method if using browsers that are Not Chrome! "
71027112 'The browser detected was: "%s".' % (method, browser_name)
71037113 )
71047114 raise NotUsingChromeException(message)
71057115
7116+ def __fail_if_not_using_chromium(self, method):
7117+ browser_name = self.driver.capabilities["browserName"]
7118+ if not self.is_chromium():
7119+ message = (
7120+ 'Error: "%s" should only be called by tests '
7121+ 'running with a Chromium browser! (Chrome or Edge) '
7122+ 'You should add an "if" statement to your code before calling '
7123+ "this method if using browsers that are Not Chromium! "
7124+ 'The browser detected was: "%s".' % (method, browser_name)
7125+ )
7126+ raise NotUsingChromiumException(message)
7127+
71067128 def get_chrome_version(self):
71077129 self.__check_scope()
71087130 self.__fail_if_not_using_chrome("get_chrome_version()")
@@ -7113,6 +7135,11 @@ def get_chrome_version(self):
71137135 chrome_version = driver_capabilities["browserVersion"]
71147136 return chrome_version
71157137
7138+ def get_chromium_version(self):
7139+ self.__check_scope()
7140+ self.__fail_if_not_using_chromium("get_chromium_version()")
7141+ return self.__get_major_browser_version()
7142+
71167143 def get_chromedriver_version(self):
71177144 self.__check_scope()
71187145 self.__fail_if_not_using_chrome("get_chromedriver_version()")
@@ -7121,14 +7148,19 @@ def get_chromedriver_version(self):
71217148 chromedriver_version = chromedriver_version.split(" ")[0]
71227149 return chromedriver_version
71237150
7124- def is_chromedriver_too_old(self):
7125- """Before chromedriver 73, there was no version check, which
7126- means it's possible to run a new Chrome with old drivers."""
7151+ def get_chromium_driver_version(self):
71277152 self.__check_scope()
7128- self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
7129- if int(self.get_chromedriver_version().split(".")[0]) < 73:
7130- return True # chromedriver is too old! Please upgrade!
7131- return False
7153+ self.__fail_if_not_using_chromium("get_chromium_version()")
7154+ driver_version = None
7155+ if "chrome" in self.driver.capabilities:
7156+ chrome_dict = self.driver.capabilities["chrome"]
7157+ driver_version = chrome_dict["chromedriverVersion"]
7158+ driver_version = driver_version.split(" ")[0]
7159+ elif "msedge" in self.driver.capabilities:
7160+ edge_dict = self.driver.capabilities["msedge"]
7161+ driver_version = edge_dict["msedgedriverVersion"]
7162+ driver_version = driver_version.split(" ")[0]
7163+ return driver_version
71327164
71337165 def get_mfa_code(self, totp_key=None):
71347166 """Same as get_totp_code() and get_google_auth_password().
@@ -9307,8 +9339,6 @@ def __assert_eq(self, *args, **kwargs):
93079339 elif line.strip().startswith("*"):
93089340 minified_exception += line + "\n"
93099341 if minified_exception:
9310- from seleniumbase.common.exceptions import VisualException
9311-
93129342 raise VisualException(minified_exception)
93139343
93149344 def _process_visual_baseline_logs(self):
@@ -9688,8 +9718,6 @@ def __check_scope(self):
96889718 if hasattr(self, "browser"): # self.browser stores the type of browser
96899719 return # All good: setUp() already initialized variables in "self"
96909720 else:
9691- from seleniumbase.common.exceptions import OutOfScopeException
9692-
96939721 message = (
96949722 "\n It looks like you are trying to call a SeleniumBase method"
96959723 "\n from outside the scope of your test class's `self` object,"
@@ -12734,9 +12762,18 @@ def __disable_beforeunload_as_needed(self):
1273412762
1273512763 ############
1273612764
12765+ @decorators.deprecated("The Driver Manager prevents old drivers.")
12766+ def is_chromedriver_too_old(self):
12767+ """Before chromedriver 73, there was no version check, which
12768+ means it's possible to run a new Chrome with old drivers."""
12769+ self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
12770+ if int(self.get_chromedriver_version().split(".")[0]) < 73:
12771+ return True # chromedriver is too old! Please upgrade!
12772+ return False
12773+
1273712774 @decorators.deprecated("You should use re.escape() instead.")
1273812775 def jq_format(self, code):
12739- # DEPRECATED - re.escape() already performs the intended action.
12776+ # DEPRECATED - re.escape() already performs this action.
1274012777 return js_utils._jq_format(code)
1274112778
1274212779 ############
0 commit comments