From b0210b301ab6e85d9bf7f86493aee2074ec91a69 Mon Sep 17 00:00:00 2001 From: Anilabha Datta Date: Fri, 15 Mar 2024 03:47:06 +0530 Subject: [PATCH 1/4] update: get binary version of chrome in windows --- seleniumbase/core/detect_b_ver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index 8e728829308..689d48a8d66 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -7,6 +7,8 @@ import subprocess import sys +from seleniumbase.fixtures import shared_utils + class File(object): def __init__(self, stream): @@ -233,7 +235,10 @@ def get_browser_version_from_binary(binary_location): try: if binary_location.count(r"\ ") != binary_location.count(" "): binary_location = binary_location.replace(" ", r"\ ") - cmd_mapping = binary_location + " --version" + if shared_utils.is_windows(): + binary_location = f'powershell -command "&{{(Get-Item {binary_location}).VersionInfo.ProductVersion}}"' + else: + cmd_mapping = binary_location + " --version" pattern = r"\d+\.\d+\.\d+" quad_pattern = r"\d+\.\d+\.\d+\.\d+" quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) From 1dd71eda22e99c26cf1061df9a2d3bc2588729d8 Mon Sep 17 00:00:00 2001 From: Anilabha Datta Date: Sat, 16 Mar 2024 15:00:19 +0530 Subject: [PATCH 2/4] windows binary path version fix --- seleniumbase/core/detect_b_ver.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index 9fbf3b103a6..4dc5a7b8f95 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -236,27 +236,19 @@ def get_browser_version_from_binary(binary_location): path = binary_location if binary_location.count(r"\ ") != binary_location.count(" "): binary_location = binary_location.replace(" ", r"\ ") - if shared_utils.is_windows(): - binary_location = f'powershell -command "&{{(Get-Item {binary_location}).VersionInfo.ProductVersion}}"' - else: - cmd_mapping = binary_location + " --version" + cmd_mapping = binary_location + " --version" pattern = r"\d+\.\d+\.\d+" quad_pattern = r"\d+\.\d+\.\d+\.\d+" - quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) - if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0 - return quad_version - version = read_version_from_cmd(cmd_mapping, pattern) - if not version and os_name() == OSType.WIN and os.path.exists(path): + if os_name() == OSType.WIN and os.path.exists(path): path = path.replace(r"\ ", r" ").replace("\\", "\\\\") cmd_mapping = ( '''powershell -command "&{(Get-Item '%s')''' '''.VersionInfo.ProductVersion}"''' % path ) - quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) - if quad_version and len(str(quad_version)) >= 9: - return quad_version - version = read_version_from_cmd(cmd_mapping, pattern) - return version + quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) + if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0 + return quad_version + return read_version_from_cmd(cmd_mapping, pattern) except Exception: return None From d74bc778cc37d159928228197991d15a8617a431 Mon Sep 17 00:00:00 2001 From: Anilabha Datta Date: Sat, 16 Mar 2024 15:02:12 +0530 Subject: [PATCH 3/4] cleanup --- seleniumbase/core/detect_b_ver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index 4dc5a7b8f95..a405d5c1f92 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -7,8 +7,6 @@ import subprocess import sys -from seleniumbase.fixtures import shared_utils - class File(object): def __init__(self, stream): From 269eb1f221cd78134b590bc781d497d767d23131 Mon Sep 17 00:00:00 2001 From: Anilabha Datta Date: Sat, 16 Mar 2024 16:01:30 +0530 Subject: [PATCH 4/4] added backup version getter --- seleniumbase/core/detect_b_ver.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index a405d5c1f92..22d21baba8d 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -234,7 +234,6 @@ def get_browser_version_from_binary(binary_location): path = binary_location if binary_location.count(r"\ ") != binary_location.count(" "): binary_location = binary_location.replace(" ", r"\ ") - cmd_mapping = binary_location + " --version" pattern = r"\d+\.\d+\.\d+" quad_pattern = r"\d+\.\d+\.\d+\.\d+" if os_name() == OSType.WIN and os.path.exists(path): @@ -243,6 +242,17 @@ def get_browser_version_from_binary(binary_location): '''powershell -command "&{(Get-Item '%s')''' '''.VersionInfo.ProductVersion}"''' % path ) + try: + quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) + if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0 + return quad_version + version = read_version_from_cmd(cmd_mapping, pattern) + if version: + return version + except Exception: + ''' Powershell is not available, use --version instead ''' + pass + cmd_mapping = binary_location + " --version" quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0 return quad_version