Skip to content

Commit dfc8a72

Browse files
committed
feat: Add ability to use secure WebSocket to listen Logcat messages
1 parent e62b395 commit dfc8a72

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/main/java/io/appium/java_client/android/ListensToLogcatMessages.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import io.appium.java_client.ExecutesMethod;
2121
import io.appium.java_client.ws.StringWebSocketClient;
2222
import org.openqa.selenium.remote.RemoteWebDriver;
23+
import org.openqa.selenium.remote.SessionId;
2324

2425
import java.net.URI;
25-
import java.net.URISyntaxException;
2626
import java.util.function.Consumer;
2727

2828
import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
@@ -36,7 +36,7 @@ public interface ListensToLogcatMessages extends ExecutesMethod {
3636
* is assigned to the default port (4723).
3737
*/
3838
default void startLogcatBroadcast() {
39-
startLogcatBroadcast("127.0.0.1", DEFAULT_APPIUM_PORT);
39+
startLogcatBroadcast("127.0.0.1");
4040
}
4141

4242
/**
@@ -49,21 +49,42 @@ default void startLogcatBroadcast(String host) {
4949
startLogcatBroadcast(host, DEFAULT_APPIUM_PORT);
5050
}
5151

52+
/**
53+
* Start logcat messages broadcast via web socket.
54+
* This method assumes that Appium server is assigned to the default port (4723).
55+
*
56+
* @param host the name of the host where Appium server is running
57+
* @param useSecureConnection If true, secure WebSocket specification is used ('wss' scheme), otherwise - plain
58+
* WebSocket ('ws' scheme)
59+
*/
60+
default void startLogcatBroadcast(String host, boolean useSecureConnection) {
61+
startLogcatBroadcast(host, DEFAULT_APPIUM_PORT, useSecureConnection);
62+
}
63+
5264
/**
5365
* Start logcat messages broadcast via web socket.
5466
*
5567
* @param host the name of the host where Appium server is running
5668
* @param port the port of the host where Appium server is running
5769
*/
5870
default void startLogcatBroadcast(String host, int port) {
71+
startLogcatBroadcast(host, port, false);
72+
}
73+
74+
/**
75+
* Start logcat messages broadcast via web socket.
76+
*
77+
* @param host the name of the host where Appium server is running
78+
* @param port the port of the host where Appium server is running
79+
* @param useSecureConnection If true, secure WebSocket specification is used ('wss' scheme), otherwise - plain
80+
* WebSocket ('ws' scheme)
81+
*/
82+
default void startLogcatBroadcast(String host, int port, boolean useSecureConnection) {
5983
CommandExecutionHelper.executeScript(this, "mobile: startLogsBroadcast");
60-
final URI endpointUri;
61-
try {
62-
endpointUri = new URI(String.format("ws://%s:%s/ws/session/%s/appium/device/logcat",
63-
host, port, ((RemoteWebDriver) this).getSessionId()));
64-
} catch (URISyntaxException e) {
65-
throw new IllegalArgumentException(e);
66-
}
84+
String scheme = useSecureConnection ? "wss" : "ws";
85+
SessionId sessionId = ((RemoteWebDriver) this).getSessionId();
86+
URI endpointUri = URI.create(String.format("%s://%s:%s/ws/session/%s/appium/device/logcat", scheme, host,
87+
port, sessionId));
6788
getLogcatClient().connect(endpointUri);
6889
}
6990

0 commit comments

Comments
 (0)