Skip to content

Commit 64430ec

Browse files
committed
[dotnet] there is more than one place that needs selenium manager logic added
1 parent 70d1ab1 commit 64430ec

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

dotnet/src/webdriver/DriverService.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,23 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
6565
string executablePath = Path.Combine(servicePath, driverServiceExecutableName);
6666
if (!File.Exists(executablePath))
6767
{
68-
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
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+
}
6985
}
7086

7187
this.driverServicePath = servicePath;
@@ -296,7 +312,21 @@ protected static string FindDriverServiceExecutable(string executableName, Uri d
296312

297313
if (string.IsNullOrEmpty(serviceDirectory))
298314
{
299-
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));
315+
try
316+
{
317+
serviceDirectory = Path.GetDirectoryName(SeleniumManager.DriverPath(executableName));
318+
}
319+
catch (Exception e)
320+
{
321+
// No-op; entirely a fall-back feature
322+
}
323+
324+
if (string.IsNullOrEmpty(serviceDirectory))
325+
{
326+
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture,
327+
"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}.",
328+
executableName, downloadUrl));
329+
}
300330
}
301331

302332
return serviceDirectory;

0 commit comments

Comments
 (0)