From bc8ff6a2e2ed5dc87c6383828efc643b1d40a2df Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 15 Sep 2023 16:15:44 -0500 Subject: [PATCH] redo all of this so that environment variable includes file name --- dotnet/src/webdriver/SeleniumManager.cs | 23 ++++++----------- .../selenium/manager/SeleniumManager.java | 3 +-- .../common/seleniumManager.js | 4 +-- .../webdriver/common/selenium_manager.py | 25 ++++++++----------- .../webdriver/common/selenium_manager.rb | 6 ++--- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/dotnet/src/webdriver/SeleniumManager.cs b/dotnet/src/webdriver/SeleniumManager.cs index eb05cdd7de7f2..fd151e48e9f40 100644 --- a/dotnet/src/webdriver/SeleniumManager.cs +++ b/dotnet/src/webdriver/SeleniumManager.cs @@ -40,31 +40,24 @@ static SeleniumManager() { var currentDirectory = AppContext.BaseDirectory; - string binary; string file = "selenium-manager"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + string binary = $"selenium-manager/linux/{file}"; + + if (Environment.GetEnvironmentVariable("SE_MANAGER_PATH") != null) { - file = "selenium-manager.exe"; - binary = $"selenium-manager/windows/{file}"; + binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH"); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - binary = $"selenium-manager/linux/{file}"; + file = "selenium-manager.exe"; + binary = $"selenium-manager/windows/{file}"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { binary = $"selenium-manager/macos/{file}"; } - else - { - throw new WebDriverException("Selenium Manager did not find supported operating system"); - } - if (Environment.GetEnvironmentVariable("SE_MANAGER_PATH") != null) - { - binaryFullPath = Path.Combine(Environment.GetEnvironmentVariable("SE_MANAGER_PATH"), file); - } - else + if (binaryFullPath == null) { binaryFullPath = Path.Combine(currentDirectory, binary); } diff --git a/java/src/org/openqa/selenium/manager/SeleniumManager.java b/java/src/org/openqa/selenium/manager/SeleniumManager.java index 630fd488d4d00..084b4f7bba126 100644 --- a/java/src/org/openqa/selenium/manager/SeleniumManager.java +++ b/java/src/org/openqa/selenium/manager/SeleniumManager.java @@ -171,8 +171,7 @@ private synchronized Path getBinary() { } String binaryPath; if (System.getenv("SE_MANAGER_PATH") != null) { - folder = System.getenv("SE_MANAGER_PATH"); - binary = Paths.get(String.format("%s/%s%s", folder, SELENIUM_MANAGER, extension)); + binary = Paths.get(System.getenv("SE_MANAGER_PATH")); } else { binaryPath = String.format("%s/%s%s", folder, SELENIUM_MANAGER, extension); try (InputStream inputStream = this.getClass().getResourceAsStream(binaryPath)) { diff --git a/javascript/node/selenium-webdriver/common/seleniumManager.js b/javascript/node/selenium-webdriver/common/seleniumManager.js index f60c77ceb026a..1c063aa06bc39 100644 --- a/javascript/node/selenium-webdriver/common/seleniumManager.js +++ b/javascript/node/selenium-webdriver/common/seleniumManager.js @@ -44,9 +44,9 @@ function getBinary() { const file = directory === 'windows' ? 'selenium-manager.exe' : 'selenium-manager' - const seleniumManagerBasePath = process.env.SE_MANAGER_PATH || path.join(__dirname, '..', '/bin', directory) + let seleniumManagerBasePath = path.join(__dirname, '..', '/bin') - const filePath = path.join(seleniumManagerBasePath, file) + const filePath = process.env.SE_MANAGER_PATH || path.join(seleniumManagerBasePath, directory, file) if (!fs.existsSync(filePath)) { throw new Error(`Unable to obtain Selenium Manager at ${filePath}`) diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index 480cfde70f958..4698d98e30354 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -40,23 +40,18 @@ def get_binary() -> Path: :Returns: The Selenium Manager executable location """ - platform = sys.platform - - dirs = { - "darwin": "macos", - "win32": "windows", - "cygwin": "windows", - } - - directory = dirs.get(platform) if dirs.get(platform) else platform - - file = "selenium-manager.exe" if directory == "windows" else "selenium-manager" - + directory = "linux" + file = "selenium-manager" if os.getenv("SE_MANAGER_PATH"): directory = os.getenv("SE_MANAGER_PATH") - path = f"{Path(directory)}/{file}" - else: - path = Path(__file__).parent.joinpath(directory, file) + file = "" + if sys.platform == "darwin": + directory = "macos" + elif sys.platform in ("win32", "cygwin"): + directory = "windows" + file = "selenium-manager.exe" + + path = Path(__file__).parent.joinpath(directory, file) if not path.is_file() and os.environ["CONDA_PREFIX"]: # conda has a separate package selenium-manager, installs in bin diff --git a/rb/lib/selenium/webdriver/common/selenium_manager.rb b/rb/lib/selenium/webdriver/common/selenium_manager.rb index 03618f619ed7f..1268629aa66c2 100644 --- a/rb/lib/selenium/webdriver/common/selenium_manager.rb +++ b/rb/lib/selenium/webdriver/common/selenium_manager.rb @@ -31,7 +31,7 @@ class << self attr_writer :bin_path def bin_path - @bin_path ||= ENV.fetch('SE_MANAGER_PATH', '../../../../../bin') + @bin_path ||= '../../../../../bin' end # @param [Options] options browser options. @@ -80,10 +80,10 @@ def binary '/windows/selenium-manager.exe' elsif Platform.mac? '/macos/selenium-manager' - elsif Platform.linux? + else '/linux/selenium-manager' end - location = File.expand_path(path, __FILE__) + location = ENV.fetch('SE_MANAGER_PATH', File.expand_path(path, __FILE__)) begin Platform.assert_file(location)