Skip to content

Commit

Permalink
redo all of this so that environment variable includes file name
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 16, 2023
1 parent 1687fd5 commit bc8ff6a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
23 changes: 8 additions & 15 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/common/seleniumManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
25 changes: 10 additions & 15 deletions py/selenium/webdriver/common/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions rb/lib/selenium/webdriver/common/selenium_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bc8ff6a

Please sign in to comment.