@@ -61,6 +61,12 @@ def test_anything(self):
61
61
from seleniumbase import config as sb_config
62
62
from seleniumbase.__version__ import __version__
63
63
from seleniumbase.common import decorators
64
+ from seleniumbase.common.exceptions import (
65
+ NotUsingChromeException,
66
+ NotUsingChromiumException,
67
+ OutOfScopeException,
68
+ VisualException,
69
+ )
64
70
from seleniumbase.config import settings
65
71
from seleniumbase.core import download_helper
66
72
from seleniumbase.core import log_helper
@@ -6427,11 +6433,15 @@ def save_element_as_image_file(
6427
6433
def download_file(self, file_url, destination_folder=None):
6428
6434
"""Downloads the file from the url to the destination folder.
6429
6435
If no destination folder is specified, the default one is used.
6430
- (The default [Downloads Folder] = "./downloaded_files")"""
6431
- if not destination_folder:
6432
- destination_folder = constants.Files.DOWNLOADS_FOLDER
6433
- if not os.path.exists(destination_folder):
6434
- os.makedirs(destination_folder)
6436
+ (The default folder for downloads is "./downloaded_files")"""
6437
+ download_file_lock = fasteners.InterProcessLock(
6438
+ constants.MultiBrowser.DOWNLOAD_FILE_LOCK
6439
+ )
6440
+ with download_file_lock:
6441
+ if not destination_folder:
6442
+ destination_folder = constants.Files.DOWNLOADS_FOLDER
6443
+ if not os.path.exists(destination_folder):
6444
+ os.makedirs(destination_folder)
6435
6445
page_utils._download_file_to(file_url, destination_folder)
6436
6446
if self.recorder_mode:
6437
6447
url = self.get_current_url()
@@ -6489,6 +6499,12 @@ def get_browser_downloads_folder(self):
6489
6499
and self.headless
6490
6500
):
6491
6501
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(".")
6492
6508
else:
6493
6509
return download_helper.get_downloads_folder()
6494
6510
return os.path.join(os.path.expanduser("~"), "downloads")
@@ -7088,17 +7104,27 @@ def __fail_if_not_using_chrome(self, method):
7088
7104
if browser_name.lower() == "chrome":
7089
7105
chrome = True
7090
7106
if not chrome:
7091
- from seleniumbase.common.exceptions import NotUsingChromeException
7092
-
7093
7107
message = (
7094
- 'Error: "%s" should only be called '
7095
- 'by tests running with self. browser == " chrome"! '
7108
+ 'Error: "%s" should only be called by tests '
7109
+ 'running with "-- browser=chrome" / "-- chrome"! '
7096
7110
'You should add an "if" statement to your code before calling '
7097
7111
"this method if using browsers that are Not Chrome! "
7098
7112
'The browser detected was: "%s".' % (method, browser_name)
7099
7113
)
7100
7114
raise NotUsingChromeException(message)
7101
7115
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
+
7102
7128
def get_chrome_version(self):
7103
7129
self.__check_scope()
7104
7130
self.__fail_if_not_using_chrome("get_chrome_version()")
@@ -7109,6 +7135,11 @@ def get_chrome_version(self):
7109
7135
chrome_version = driver_capabilities["browserVersion"]
7110
7136
return chrome_version
7111
7137
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
+
7112
7143
def get_chromedriver_version(self):
7113
7144
self.__check_scope()
7114
7145
self.__fail_if_not_using_chrome("get_chromedriver_version()")
@@ -7117,14 +7148,19 @@ def get_chromedriver_version(self):
7117
7148
chromedriver_version = chromedriver_version.split(" ")[0]
7118
7149
return chromedriver_version
7119
7150
7120
- def is_chromedriver_too_old(self):
7121
- """Before chromedriver 73, there was no version check, which
7122
- means it's possible to run a new Chrome with old drivers."""
7151
+ def get_chromium_driver_version(self):
7123
7152
self.__check_scope()
7124
- self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
7125
- if int(self.get_chromedriver_version().split(".")[0]) < 73:
7126
- return True # chromedriver is too old! Please upgrade!
7127
- 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
7128
7164
7129
7165
def get_mfa_code(self, totp_key=None):
7130
7166
"""Same as get_totp_code() and get_google_auth_password().
@@ -9303,8 +9339,6 @@ def __assert_eq(self, *args, **kwargs):
9303
9339
elif line.strip().startswith("*"):
9304
9340
minified_exception += line + "\n"
9305
9341
if minified_exception:
9306
- from seleniumbase.common.exceptions import VisualException
9307
-
9308
9342
raise VisualException(minified_exception)
9309
9343
9310
9344
def _process_visual_baseline_logs(self):
@@ -9684,8 +9718,6 @@ def __check_scope(self):
9684
9718
if hasattr(self, "browser"): # self.browser stores the type of browser
9685
9719
return # All good: setUp() already initialized variables in "self"
9686
9720
else:
9687
- from seleniumbase.common.exceptions import OutOfScopeException
9688
-
9689
9721
message = (
9690
9722
"\n It looks like you are trying to call a SeleniumBase method"
9691
9723
"\n from outside the scope of your test class's `self` object,"
@@ -12730,9 +12762,18 @@ def __disable_beforeunload_as_needed(self):
12730
12762
12731
12763
############
12732
12764
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
+
12733
12774
@decorators.deprecated("You should use re.escape() instead.")
12734
12775
def jq_format(self, code):
12735
- # DEPRECATED - re.escape() already performs the intended action.
12776
+ # DEPRECATED - re.escape() already performs this action.
12736
12777
return js_utils._jq_format(code)
12737
12778
12738
12779
############
0 commit comments