Skip to content

Commit

Permalink
[dotnet] Rework usage of selenium manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko authored and titusfortner committed Oct 31, 2022
1 parent 2e416b8 commit 70d1ab1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
19 changes: 2 additions & 17 deletions dotnet/src/webdriver/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,7 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
string executablePath = Path.Combine(servicePath, driverServiceExecutableName);
if (!File.Exists(executablePath))
{
try
{
executablePath = SeleniumManager.DriverPath(driverServiceExecutableName);
}
catch (Exception e)
{
// No-op; entirely a fall-back feature
}

if (File.Exists(executablePath))
{
servicePath = Path.GetDirectoryName(executablePath);
}
else
{
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
}
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
}

this.driverServicePath = servicePath;
Expand Down Expand Up @@ -309,6 +293,7 @@ public void Start()
protected static string FindDriverServiceExecutable(string executableName, Uri downloadUrl)
{
string serviceDirectory = FileUtilities.FindFile(executableName);

if (string.IsNullOrEmpty(serviceDirectory))
{
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The {0} file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at {1}.", executableName, downloadUrl));
Expand Down
34 changes: 4 additions & 30 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,13 @@ private static string Binary
{
if (string.IsNullOrEmpty(binary))
{
string folder = "windows";
string extension = ".exe";

// TODO Identify runtime platform
if (!Environment.OSVersion.Platform.ToString().StartsWith("Win"))
{
throw new WebDriverException("Selenium Manager only supports Windows in .NET at this time");
}

try
{
string name = "selenium-manager-" + folder;
using (Stream fileStream = ResourceUtilities.GetResourceStream(name, name))
{
using (BinaryReader binReader = new BinaryReader(fileStream, Encoding.ASCII))
{
byte[] fileBytes = binReader.ReadBytes((int)fileStream.Length);
string directoryName = string.Format(CultureInfo.InvariantCulture, "webdriver.{0}",
Guid.NewGuid().ToString("N"));
var path = Path.Combine(Path.GetTempPath(), directoryName + "/" + folder);
Directory.CreateDirectory(path);
var filePath = Path.Combine(path, "selenium-manager" + extension);

using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create)))
{
binWriter.Flush();
binWriter.Write(fileBytes);
}
binary = filePath;
}
}
}
catch (Exception ex)
{
throw new WebDriverException("Unable to obtain Selenium Manager", ex);
}
binary = "selenium-manager/windows/selenium-manager.exe";
}

return binary;
Expand All @@ -127,10 +99,12 @@ private static string RunCommand(string fileName, string arguments)
process.StartInfo.RedirectStandardOutput = true;

string output;

try
{
process.Start();
output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
}
catch (Exception ex)
{
Expand Down

0 comments on commit 70d1ab1

Please sign in to comment.