|
19 | 19 | import subprocess |
20 | 20 | import sys |
21 | 21 | from pathlib import Path |
22 | | -from typing import Tuple |
| 22 | +from typing import List |
23 | 23 |
|
24 | 24 | from selenium.common.exceptions import SeleniumManagerException |
25 | 25 | from selenium.webdriver.common.options import BaseOptions |
@@ -87,37 +87,36 @@ def driver_location(self, options: BaseOptions) -> str: |
87 | 87 |
|
88 | 88 | browser = allowed_browsers[browser] |
89 | 89 |
|
90 | | - binary, browser_flag, browser, output_flag, output = ( |
91 | | - str(self.get_binary()), |
92 | | - "--browser", |
93 | | - browser, |
94 | | - "--output", |
95 | | - "json", |
96 | | - ) |
97 | | - result = self.run((binary, browser_flag, browser, output_flag, output)) |
| 90 | + args = [str(self.get_binary()), "--browser", browser, "--output", "json"] |
| 91 | + |
| 92 | + if options.browser_version: |
| 93 | + args.append("--browser-version") |
| 94 | + args.append(str(options.browser_version)) |
| 95 | + |
| 96 | + result = self.run(args) |
98 | 97 | executable = result.split("\t")[-1].strip() |
99 | 98 | logger.debug(f"Using driver at: {executable}") |
100 | 99 | return executable |
101 | 100 |
|
102 | 101 | @staticmethod |
103 | | - def run(args: Tuple[str, str, str, str, str]) -> str: |
| 102 | + def run(args: List[str]) -> str: |
104 | 103 | """ |
105 | 104 | Executes the Selenium Manager Binary. |
106 | 105 | :Args: |
107 | 106 | - args: the components of the command being executed. |
108 | 107 | :Returns: The log string containing the driver location. |
109 | 108 | """ |
110 | 109 | command = " ".join(args) |
111 | | - logger.debug(f"Executing: {command}") |
| 110 | + logger.info(f"Executing: {command}") |
112 | 111 | completed_proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
113 | 112 | stdout = completed_proc.stdout.decode("utf-8").rstrip("\n") |
114 | 113 | stderr = completed_proc.stderr.decode("utf-8").rstrip("\n") |
115 | 114 | output = json.loads(stdout) |
116 | 115 | result = output["result"]["message"] |
117 | 116 | if completed_proc.returncode: |
118 | | - raise SeleniumManagerException(f"Selenium manager failed for: {command}.\n{result}{stderr}") |
| 117 | + raise SeleniumManagerException(f"Selenium Manager failed for: {command}.\n{result}{stderr}") |
119 | 118 | else: |
120 | | - # Selenium Manager exited 0 successfully, return executable path and print warnings (if any) |
| 119 | + # Selenium Manager exited successfully, return executable path and print warnings |
121 | 120 | for item in output["logs"]: |
122 | 121 | if item["level"] == "WARN": |
123 | 122 | logger.warning(item["message"]) |
|
0 commit comments