Skip to content

Commit dc9ab40

Browse files
committed
[java] create special driver exception for referencing documentation
1 parent b3ab716 commit dc9ab40

File tree

3 files changed

+59
-17
lines changed

3 files changed

+59
-17
lines changed

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private synchronized File getBinary() {
170170
}
171171
binary.setExecutable(true);
172172
} catch (Exception e) {
173-
throw new WebDriverException("Unable to obtain Selenium Manager", e);
173+
throw new WebDriverException("Unable to obtain Selenium Manager Binary", e);
174174
}
175175
}
176176
return binary;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.remote;
19+
20+
import org.openqa.selenium.Capabilities;
21+
import org.openqa.selenium.WebDriverException;
22+
import org.openqa.selenium.remote.service.DriverService;
23+
24+
/**
25+
* Thrown by {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}.
26+
*/
27+
public class NoSuchDriverException extends WebDriverException {
28+
29+
private static final String SUPPORT_URL = BASE_SUPPORT_URL + "/driver_location/";
30+
31+
public NoSuchDriverException(String reason) {
32+
super(reason);
33+
}
34+
35+
public NoSuchDriverException(String reason, Throwable cause) {
36+
super(reason, cause);
37+
}
38+
39+
@Override
40+
public String getSupportUrl() {
41+
return SUPPORT_URL;
42+
}
43+
}

java/src/org/openqa/selenium/remote/service/DriverFinder.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.openqa.selenium.internal.Require;
77
import org.openqa.selenium.manager.SeleniumManager;
88
import org.openqa.selenium.os.ExecutableFinder;
9+
import org.openqa.selenium.remote.NoSuchDriverException;
910

1011
public class DriverFinder {
1112

@@ -25,24 +26,22 @@ public static String getPath(DriverService service, Capabilities options) {
2526
try {
2627
exePath = SeleniumManager.getInstance().getDriverPath(options);
2728
} catch (Exception e) {
28-
LOG.warning(
29-
String.format(
30-
"Unable to obtain %s using Selenium Manager: %s",
31-
service.getDriverName(), e.getMessage()));
29+
throw new NoSuchDriverException(String.format(
30+
"Unable to obtain: %s", options), e);
3231
}
3332
}
3433

35-
String validPath =
36-
Require.state("The path to the driver executable", exePath)
37-
.nonNull(
38-
"Unable to locate the %s executable; for more information on how to install"
39-
+ " drivers, see"
40-
+ " https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/",
41-
service.getDriverName());
42-
43-
File exe = new File(validPath);
44-
Require.state("The driver executable", exe).isFile();
45-
Require.stateCondition(exe.canExecute(), "It must be an executable file: %s", exe);
46-
return validPath;
34+
String message = "";
35+
if (exePath == null) {
36+
message = String.format("Unable to locate or obtain %s", service.getDriverName());
37+
} else if (!new File(exePath).exists()) {
38+
message = String.format("%s located at %s, but invalid", service.getDriverName(), exePath);
39+
} else if (!new File(exePath).canExecute()) {
40+
message = String.format("%s located at %s, cannot be executed", service.getDriverName(), exePath);
41+
} else {
42+
return exePath;
43+
}
44+
45+
throw new NoSuchDriverException(message);
4746
}
4847
}

0 commit comments

Comments
 (0)