Skip to content

Commit b003857

Browse files
iampopovichdiemol
andauthored
[py] simplify driver binary and driver location selecting (#11864)
* simplify driver selection * lint fixes * simplify binary selection * fix tests * fix test --------- Co-authored-by: Diego Molina <[email protected]>
1 parent f28f1df commit b003857

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

py/selenium/webdriver/common/selenium_manager.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ def get_binary() -> Path:
4141
4242
:Returns: The Selenium Manager executable location
4343
"""
44-
directory = sys.platform
45-
if directory == "darwin":
46-
directory = "macos"
47-
elif directory in ("win32", "cygwin"):
48-
directory = "windows"
44+
platform = sys.platform
45+
46+
dirs = {
47+
"darwin": "macos",
48+
"win32": "windows",
49+
"cygwin": "windows",
50+
}
51+
52+
directory = dirs.get(platform) if dirs.get(platform) else platform
4953

5054
file = "selenium-manager.exe" if directory == "windows" else "selenium-manager"
5155

@@ -64,12 +68,20 @@ def driver_location(self, browser: str) -> str:
6468
- browser: which browser to get the driver path for.
6569
:Returns: The driver path to use
6670
"""
67-
allowed = ("chrome", "firefox", "edge", "ie")
68-
if browser not in allowed:
69-
raise SeleniumManagerException(f"{browser} is not a valid browser. Choose one of: {allowed}")
7071

71-
if browser == "ie":
72-
browser = "iexplorer"
72+
allowed_browsers = {
73+
"chrome": "chrome",
74+
"firefox": "firefox",
75+
"edge": "edge",
76+
"ie": "iexplorer",
77+
}
78+
79+
if browser not in allowed_browsers.keys():
80+
raise SeleniumManagerException(
81+
f"{browser} is not a valid browser. Choose one of: {list(allowed_browsers.keys())}"
82+
)
83+
84+
browser = allowed_browsers[browser]
7385

7486
binary, browser_flag, browser, output_flag, output = (
7587
str(self.get_binary()),

py/test/selenium/webdriver/common/selenium_manager_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def test_non_supported_browser_raises_sme():
25-
msg = r"foo is not a valid browser. Choose one of: \('chrome', 'firefox', 'edge', 'ie'\)"
25+
msg = r"foo is not a valid browser. Choose one of: \['chrome', 'firefox', 'edge', 'ie'\]"
2626
with pytest.raises(SeleniumManagerException, match=msg):
2727
_ = SeleniumManager().driver_location("foo")
2828

0 commit comments

Comments
 (0)