|
19 | 19 | sbase get chromedriver stable |
20 | 20 | sbase get chromedriver beta |
21 | 21 | sbase get chromedriver -p |
| 22 | + sbase get chromium |
22 | 23 | sbase get cft 131 |
23 | 24 | sbase get chs |
24 | 25 | Output: |
|
46 | 47 | from seleniumbase import drivers # webdriver storage folder for SeleniumBase |
47 | 48 | from seleniumbase.drivers import cft_drivers # chrome-for-testing |
48 | 49 | from seleniumbase.drivers import chs_drivers # chrome-headless-shell |
| 50 | +from seleniumbase.drivers import chromium_drivers # base chromium |
49 | 51 |
|
50 | 52 | urllib3.disable_warnings() |
51 | 53 | ARCH = platform.architecture()[0] |
52 | 54 | IS_ARM_MAC = shared_utils.is_arm_mac() |
53 | 55 | IS_MAC = shared_utils.is_mac() |
| 56 | +IS_ARM_LINUX = shared_utils.is_arm_linux() |
54 | 57 | IS_LINUX = shared_utils.is_linux() |
55 | 58 | IS_WINDOWS = shared_utils.is_windows() |
56 | 59 | DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__)) |
57 | 60 | DRIVER_DIR_CFT = os.path.dirname(os.path.realpath(cft_drivers.__file__)) |
58 | 61 | DRIVER_DIR_CHS = os.path.dirname(os.path.realpath(chs_drivers.__file__)) |
| 62 | +DRIVER_DIR_CHROMIUM = os.path.dirname( |
| 63 | + os.path.realpath(chromium_drivers.__file__) |
| 64 | +) |
59 | 65 | LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems |
60 | 66 | DEFAULT_CHROMEDRIVER_VERSION = "114.0.5735.90" # (If can't find LATEST_STABLE) |
61 | 67 | DEFAULT_GECKODRIVER_VERSION = "v0.36.0" |
@@ -203,6 +209,59 @@ def get_cft_latest_version_from_milestone(milestone): |
203 | 209 | return url_request.json()["milestones"][milestone]["version"] |
204 | 210 |
|
205 | 211 |
|
| 212 | +def get_chromium_channel_revision(platform_code, channel): |
| 213 | + """Snapshots only exist for revisions where a build occurred. |
| 214 | + Therefore, not all found revisions will lead to snapshots.""" |
| 215 | + platform_key = None |
| 216 | + if platform_code in ["Mac_Arm", "Mac"]: |
| 217 | + platform_key = "Mac" |
| 218 | + elif platform_code in ["Linux_x64"]: |
| 219 | + platform_key = "Linux" |
| 220 | + elif platform_code in ["Win_x64"]: |
| 221 | + platform_key = "Windows" |
| 222 | + elif platform_code in ["Win"]: |
| 223 | + platform_key = "Win32" |
| 224 | + channel_key = None |
| 225 | + if channel.lower() == "stable": |
| 226 | + channel_key = "Stable" |
| 227 | + elif channel.lower() == "beta": |
| 228 | + channel_key = "Beta" |
| 229 | + elif channel.lower() == "dev": |
| 230 | + channel_key = "Dev" |
| 231 | + elif channel.lower() == "canary": |
| 232 | + channel_key = "Canary" |
| 233 | + base_url = "https://chromiumdash.appspot.com/fetch_releases" |
| 234 | + url = f"{base_url}?channel={channel_key}&platform={platform_key}&num=1" |
| 235 | + url_request = requests_get_with_retry(url) |
| 236 | + data = None |
| 237 | + if url_request.ok: |
| 238 | + data = url_request.text |
| 239 | + else: |
| 240 | + raise Exception("Could not determine Chromium revision!") |
| 241 | + if data: |
| 242 | + try: |
| 243 | + import ast |
| 244 | + |
| 245 | + result = ast.literal_eval(data) |
| 246 | + revision = result[0]["chromium_main_branch_position"] |
| 247 | + return str(revision) |
| 248 | + except Exception: |
| 249 | + return get_latest_chromedriver_version(platform_code) |
| 250 | + else: |
| 251 | + return get_latest_chromedriver_version(platform_code) |
| 252 | + |
| 253 | + |
| 254 | +def get_chromium_latest_revision(platform_code): |
| 255 | + base_url = "https://storage.googleapis.com/chromium-browser-snapshots" |
| 256 | + url = f"{base_url}/{platform_code}/LAST_CHANGE" |
| 257 | + url_request = requests_get_with_retry(url) |
| 258 | + if url_request.ok: |
| 259 | + latest_revision = url_request.text |
| 260 | + else: |
| 261 | + raise Exception("Could not determine latest Chromium revision!") |
| 262 | + return latest_revision |
| 263 | + |
| 264 | + |
206 | 265 | def get_latest_chromedriver_version(channel="Stable"): |
207 | 266 | try: |
208 | 267 | if getattr(sb_config, "cft_lkgv_json", None): |
@@ -274,6 +333,11 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
274 | 333 | elif override.startswith("iedriver "): |
275 | 334 | extra = override.split("iedriver ")[1] |
276 | 335 | sys.argv = ["seleniumbase", "get", "iedriver", extra] |
| 336 | + elif override == "chromium": |
| 337 | + sys.argv = ["seleniumbase", "get", "chromium"] |
| 338 | + elif override.startswith("chromium "): |
| 339 | + extra = override.split("chromium ")[1] |
| 340 | + sys.argv = ["seleniumbase", "get", "chromium", extra] |
277 | 341 | elif override == "cft": |
278 | 342 | sys.argv = ["seleniumbase", "get", "cft"] |
279 | 343 | elif override.startswith("cft "): |
@@ -316,6 +380,8 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
316 | 380 | downloads_folder = DRIVER_DIR_CFT |
317 | 381 | elif override == "chs" or name == "chs": |
318 | 382 | downloads_folder = DRIVER_DIR_CHS |
| 383 | + elif override == "chromium": |
| 384 | + downloads_folder = DRIVER_DIR_CHROMIUM |
319 | 385 | expected_contents = None |
320 | 386 | platform_code = None |
321 | 387 | copy_to_path = False |
@@ -643,6 +709,31 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
643 | 709 | "https://storage.googleapis.com/chrome-for-testing-public/" |
644 | 710 | "%s/%s/%s" % (use_version, platform_code, file_name) |
645 | 711 | ) |
| 712 | + elif name == "chromium": |
| 713 | + if IS_MAC: |
| 714 | + if IS_ARM_MAC: |
| 715 | + platform_code = "Mac_Arm" |
| 716 | + else: |
| 717 | + platform_code = "Mac" |
| 718 | + file_name = "chrome-mac.zip" |
| 719 | + elif IS_LINUX: |
| 720 | + platform_code = "Linux_x64" |
| 721 | + file_name = "chrome-linux.zip" |
| 722 | + elif IS_WINDOWS: |
| 723 | + if "64" in ARCH: |
| 724 | + platform_code = "Win_x64" |
| 725 | + else: |
| 726 | + platform_code = "Win" |
| 727 | + file_name = "chrome-win.zip" |
| 728 | + revision = get_chromium_latest_revision(platform_code) |
| 729 | + msg = c2 + "Chromium revision to download" + cr |
| 730 | + p_version = c3 + revision + cr |
| 731 | + log_d("\n*** %s = %s" % (msg, p_version)) |
| 732 | + download_url = ( |
| 733 | + "https://storage.googleapis.com/chromium-browser-snapshots/" |
| 734 | + "%s/%s/%s" % (platform_code, revision, file_name) |
| 735 | + ) |
| 736 | + downloads_folder = DRIVER_DIR_CHROMIUM |
646 | 737 | elif name == "chrome-headless-shell" or name == "chs": |
647 | 738 | set_version = None |
648 | 739 | found_version = None |
@@ -1003,12 +1094,12 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
1003 | 1094 | remote_file = requests_get_with_retry(download_url) |
1004 | 1095 | with open(file_path, "wb") as file: |
1005 | 1096 | file.write(remote_file.content) |
1006 | | - log_d("%sDownload Complete!%s\n" % (c1, cr)) |
1007 | 1097 |
|
1008 | 1098 | if file_name.endswith(".zip"): |
1009 | 1099 | zip_file_path = file_path |
1010 | 1100 | zip_ref = zipfile.ZipFile(zip_file_path, "r") |
1011 | 1101 | contents = zip_ref.namelist() |
| 1102 | + log_d("%sDownload Complete!%s\n" % (c1, cr)) |
1012 | 1103 | if ( |
1013 | 1104 | len(contents) >= 1 |
1014 | 1105 | and name in ["chromedriver", "uc_driver", "geckodriver"] |
@@ -1249,6 +1340,48 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
1249 | 1340 | "Chrome for Testing was saved inside:\n%s%s\n%s\n" |
1250 | 1341 | % (pr_base_path, pr_sep, pr_folder_name) |
1251 | 1342 | ) |
| 1343 | + elif name == "chromium": |
| 1344 | + # Zip file is valid. Proceed. |
| 1345 | + driver_path = None |
| 1346 | + driver_file = None |
| 1347 | + base_path = os.sep.join(zip_file_path.split(os.sep)[:-1]) |
| 1348 | + folder_name = contents[0].split("/")[0] |
| 1349 | + folder_path = os.path.join(base_path, folder_name) |
| 1350 | + if IS_MAC or IS_LINUX: |
| 1351 | + if ( |
| 1352 | + "chromium" in folder_path |
| 1353 | + and "drivers" in folder_path |
| 1354 | + and os.path.exists(folder_path) |
| 1355 | + ): |
| 1356 | + shutil.rmtree(folder_path) |
| 1357 | + subprocess.run( |
| 1358 | + ["unzip", zip_file_path, "-d", downloads_folder] |
| 1359 | + ) |
| 1360 | + elif IS_WINDOWS: |
| 1361 | + subprocess.run( |
| 1362 | + [ |
| 1363 | + "powershell", |
| 1364 | + "Expand-Archive", |
| 1365 | + "-Path", |
| 1366 | + zip_file_path, |
| 1367 | + "-DestinationPath", |
| 1368 | + downloads_folder, |
| 1369 | + "-Force", |
| 1370 | + ] |
| 1371 | + ) |
| 1372 | + else: |
| 1373 | + zip_ref.extractall(downloads_folder) |
| 1374 | + zip_ref.close() |
| 1375 | + with suppress(Exception): |
| 1376 | + os.remove(zip_file_path) |
| 1377 | + log_d("%sUnzip Complete!%s\n" % (c2, cr)) |
| 1378 | + pr_base_path = c3 + base_path + cr |
| 1379 | + pr_sep = c3 + os.sep + cr |
| 1380 | + pr_folder_name = c3 + folder_name + cr |
| 1381 | + log_d( |
| 1382 | + "Chromium was saved inside:\n%s%s\n%s\n" |
| 1383 | + % (pr_base_path, pr_sep, pr_folder_name) |
| 1384 | + ) |
1252 | 1385 | elif name == "chrome-headless-shell" or name == "chs": |
1253 | 1386 | # Zip file is valid. Proceed. |
1254 | 1387 | driver_path = None |
@@ -1300,6 +1433,7 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
1300 | 1433 | tar = tarfile.open(file_path) |
1301 | 1434 | contents = tar.getnames() |
1302 | 1435 | if len(contents) == 1: |
| 1436 | + log_d("%sDownload Complete!%s\n" % (c1, cr)) |
1303 | 1437 | for f_name in contents: |
1304 | 1438 | # Remove existing version if exists |
1305 | 1439 | new_file = os.path.join(downloads_folder, str(f_name)) |
@@ -1337,6 +1471,7 @@ def main(override=None, intel_for_uc=None, force_uc=None): |
1337 | 1471 | else: |
1338 | 1472 | # Not a .zip file or a .tar.gz file. Just a direct download. |
1339 | 1473 | if "Driver" in file_name or "driver" in file_name: |
| 1474 | + log_d("%sDownload Complete!%s\n" % (c1, cr)) |
1340 | 1475 | log_d("Making [%s] executable ..." % file_name) |
1341 | 1476 | make_executable(file_path) |
1342 | 1477 | log_d("%s[%s] is now ready for use!%s" % (c1, file_name, cr)) |
|
0 commit comments