Skip to content

Commit d343d2c

Browse files
committed
[dotnet] add Driver Location Exception and update exception conditions
1 parent b30ec03 commit d343d2c

File tree

3 files changed

+103
-6
lines changed

3 files changed

+103
-6
lines changed

dotnet/src/webdriver/DriverFinder.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ public static DriverService VerifyDriverServicePath(DriverService service, Drive
4141
if (File.Exists(executablePath)) return service;
4242
try
4343
{
44-
string driverFullPath = SeleniumManager.DriverPath(options);
45-
service.DriverServicePath = Path.GetDirectoryName(driverFullPath);
46-
service.DriverServiceExecutableName = Path.GetFileName(driverFullPath);
47-
return service;
44+
executablePath = SeleniumManager.DriverPath(options);
45+
service.DriverServicePath = Path.GetDirectoryName(executablePath);
46+
service.DriverServiceExecutableName = Path.GetFileName(executablePath);
4847
}
4948
catch (Exception e)
5049
{
51-
throw new WebDriverException($"Unable to locate driver with path: {executablePath}, for more information on how to install drivers see https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/", e);
50+
throw new NoSuchDriverException($"Unable to obtain {service.DriverServiceExecutableName} using Selenium Manager", e);
5251
}
52+
53+
if (File.Exists(executablePath)) return service;
54+
55+
throw new NoSuchDriverException($"Unable to locate or obtain {service.DriverServiceExecutableName}");
5356
}
5457
}
5558
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// <copyright file="NoSuchDriverException.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// </copyright>
18+
19+
using System;
20+
using System.Runtime.Serialization;
21+
22+
namespace OpenQA.Selenium
23+
{
24+
/// <summary>
25+
/// The exception that is thrown when a driver is not found.
26+
/// </summary>
27+
[Serializable]
28+
public class NoSuchDriverException : NotFoundException
29+
{
30+
31+
/// <summary>
32+
/// Link to the documentation for this error
33+
/// </summary>
34+
private static string supportUrl = baseSupportUrl + "/driver_location";
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="NoSuchDriverException"/> class.
38+
/// </summary>
39+
public NoSuchDriverException()
40+
: base(GetMessage(""))
41+
{
42+
}
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="NoSuchDriverException"/> class with
46+
/// a specified error message.
47+
/// </summary>
48+
/// <param name="message">The message that describes the error.</param>
49+
public NoSuchDriverException(string message)
50+
: base(GetMessage(message))
51+
{
52+
}
53+
54+
/// <summary>
55+
/// Initializes a new instance of the <see cref="NoSuchDriverException"/> class with
56+
/// a specified error message and a reference to the inner exception that is the
57+
/// cause of this exception.
58+
/// </summary>
59+
/// <param name="message">The error message that explains the reason for the exception.</param>
60+
/// <param name="innerException">The exception that is the cause of the current exception,
61+
/// or <see langword="null"/> if no inner exception is specified.</param>
62+
public NoSuchDriverException(string message, Exception innerException)
63+
: base(GetMessage(message), innerException)
64+
{
65+
}
66+
67+
/// <summary>
68+
/// Initializes a new instance of the <see cref="NoSuchDriverException"/> class with serialized data.
69+
/// </summary>
70+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized
71+
/// object data about the exception being thrown.</param>
72+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual
73+
/// information about the source or destination.</param>
74+
protected NoSuchDriverException(SerializationInfo info, StreamingContext context)
75+
: base(info, context)
76+
{
77+
}
78+
79+
/// <summary>
80+
/// Add information about obtaining additional support from documentation to this exception.
81+
/// </summary>
82+
/// <param name="message">The original message for exception</param>
83+
/// <returns>The final message for exception</returns>
84+
protected static string GetMessage(string message)
85+
{
86+
return message + "; " + supportMsg + supportUrl;
87+
}
88+
}
89+
}

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ static SeleniumManager()
7272
#endif
7373

7474
binaryFullPath = Path.Combine(currentDirectory, binary);
75+
76+
if (!File.Exists(binaryFullPath))
77+
{
78+
throw new WebDriverException($"Unable to locate or obtain Selenium Manager binary at {binaryFullPath}");
79+
}
7580
}
7681

7782
/// <summary>
7883
/// Determines the location of the correct driver.
7984
/// </summary>
80-
/// <param name="driverName">Which driver the service needs.</param>
85+
/// <param name="options">The correct path depends on which options are being used.</param>
8186
/// <returns>
8287
/// The location of the driver.
8388
/// </returns>

0 commit comments

Comments
 (0)