Skip to content

Commit 70d1ab1

Browse files
nvborisenkotitusfortner
authored andcommitted
[dotnet] Rework usage of selenium manager
1 parent 2e416b8 commit 70d1ab1

File tree

2 files changed

+6
-47
lines changed

2 files changed

+6
-47
lines changed

dotnet/src/webdriver/DriverService.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,7 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
6565
string executablePath = Path.Combine(servicePath, driverServiceExecutableName);
6666
if (!File.Exists(executablePath))
6767
{
68-
try
69-
{
70-
executablePath = SeleniumManager.DriverPath(driverServiceExecutableName);
71-
}
72-
catch (Exception e)
73-
{
74-
// No-op; entirely a fall-back feature
75-
}
76-
77-
if (File.Exists(executablePath))
78-
{
79-
servicePath = Path.GetDirectoryName(executablePath);
80-
}
81-
else
82-
{
83-
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
84-
}
68+
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
8569
}
8670

8771
this.driverServicePath = servicePath;
@@ -309,6 +293,7 @@ public void Start()
309293
protected static string FindDriverServiceExecutable(string executableName, Uri downloadUrl)
310294
{
311295
string serviceDirectory = FileUtilities.FindFile(executableName);
296+
312297
if (string.IsNullOrEmpty(serviceDirectory))
313298
{
314299
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));

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,13 @@ private static string Binary
6969
{
7070
if (string.IsNullOrEmpty(binary))
7171
{
72-
string folder = "windows";
73-
string extension = ".exe";
74-
72+
// TODO Identify runtime platform
7573
if (!Environment.OSVersion.Platform.ToString().StartsWith("Win"))
7674
{
7775
throw new WebDriverException("Selenium Manager only supports Windows in .NET at this time");
7876
}
7977

80-
try
81-
{
82-
string name = "selenium-manager-" + folder;
83-
using (Stream fileStream = ResourceUtilities.GetResourceStream(name, name))
84-
{
85-
using (BinaryReader binReader = new BinaryReader(fileStream, Encoding.ASCII))
86-
{
87-
byte[] fileBytes = binReader.ReadBytes((int)fileStream.Length);
88-
string directoryName = string.Format(CultureInfo.InvariantCulture, "webdriver.{0}",
89-
Guid.NewGuid().ToString("N"));
90-
var path = Path.Combine(Path.GetTempPath(), directoryName + "/" + folder);
91-
Directory.CreateDirectory(path);
92-
var filePath = Path.Combine(path, "selenium-manager" + extension);
93-
94-
using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create)))
95-
{
96-
binWriter.Flush();
97-
binWriter.Write(fileBytes);
98-
}
99-
binary = filePath;
100-
}
101-
}
102-
}
103-
catch (Exception ex)
104-
{
105-
throw new WebDriverException("Unable to obtain Selenium Manager", ex);
106-
}
78+
binary = "selenium-manager/windows/selenium-manager.exe";
10779
}
10880

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

129101
string output;
102+
130103
try
131104
{
132105
process.Start();
133106
output = process.StandardOutput.ReadToEnd();
107+
process.WaitForExit();
134108
}
135109
catch (Exception ex)
136110
{

0 commit comments

Comments
 (0)