Skip to content

Commit a7eae5e

Browse files
Tune error message
1 parent 2d10f12 commit a7eae5e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class AppiumDriver extends RemoteWebDriver implements
8686
private final Set<String> absentExtensionNames = new HashSet<>();
8787
protected URI biDiUri;
8888
protected BiDi biDi;
89+
private boolean wasBiDiRequested = false;
8990

9091
/**
9192
* Creates a new instance based on command {@code executor} and {@code capabilities}.
@@ -275,12 +276,14 @@ public Optional<BiDi> maybeGetBiDi() {
275276
@Nonnull
276277
public BiDi getBiDi() {
277278
var webSocketUrl = ((BaseOptions<?>) this.capabilities).getWebSocketUrl().orElseThrow(
278-
() -> new BiDiException(
279-
String.format(
280-
"BiDi is not enabled for this driver session. "
281-
+ "Did you set %s to true?", SupportsWebSocketUrlOption.WEB_SOCKET_URL
282-
)
283-
)
279+
() -> {
280+
var suffix = wasBiDiRequested
281+
? "Do both the server and the driver declare BiDi support?"
282+
: String.format("Did you set %s to true?", SupportsWebSocketUrlOption.WEB_SOCKET_URL);
283+
return new BiDiException(String.format(
284+
"BiDi is not enabled for this driver session. %s", suffix
285+
));
286+
}
284287
);
285288
if (this.biDiUri == null) {
286289
throw new BiDiException(
@@ -332,7 +335,10 @@ && isNullOrEmpty((String) rawResponseCapabilities.get(CapabilityType.BROWSER_NAM
332335
rawResponseCapabilities.remove(CapabilityType.BROWSER_NAME);
333336
}
334337
this.capabilities = new BaseOptions<>(rawResponseCapabilities);
335-
if (Boolean.TRUE.equals(requestCapabilities.getCapability(SupportsWebSocketUrlOption.WEB_SOCKET_URL))) {
338+
this.wasBiDiRequested = Boolean.TRUE.equals(
339+
requestCapabilities.getCapability(SupportsWebSocketUrlOption.WEB_SOCKET_URL)
340+
);
341+
if (wasBiDiRequested) {
336342
this.initBiDi((BaseOptions<?>) capabilities);
337343
}
338344
setSessionId(response.getSessionId());

0 commit comments

Comments
 (0)