Skip to content

Commit

Permalink
feat: Add ability to use secure WebSocket to listen Logcat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Jul 9, 2024
1 parent b2c7d87 commit 5d4062a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import io.appium.java_client.ws.StringWebSocketClient;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.function.Consumer;

import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
Expand All @@ -36,7 +38,7 @@ public interface ListensToLogcatMessages extends ExecutesMethod {
* is assigned to the default port (4723).
*/
default void startLogcatBroadcast() {
startLogcatBroadcast("127.0.0.1", DEFAULT_APPIUM_PORT);
startLogcatBroadcast("127.0.0.1");
}

/**
Expand All @@ -56,15 +58,13 @@ default void startLogcatBroadcast(String host) {
* @param port the port of the host where Appium server is running
*/
default void startLogcatBroadcast(String host, int port) {
RemoteWebDriver remoteWebDriver = (RemoteWebDriver) this;
URL serverUrl = ((HttpCommandExecutor) remoteWebDriver.getCommandExecutor()).getAddressOfRemoteServer();
String scheme = "https".equals(serverUrl.getProtocol()) ? "wss" : "ws";
CommandExecutionHelper.executeScript(this, "mobile: startLogsBroadcast");
final URI endpointUri;
try {
endpointUri = new URI(String.format("ws://%s:%s/ws/session/%s/appium/device/logcat",
host, port, ((RemoteWebDriver) this).getSessionId()));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
getLogcatClient().connect(endpointUri);
SessionId sessionId = remoteWebDriver.getSessionId();
String endpoint = String.format("%s://%s:%s/ws/session/%s/appium/device/logcat", scheme, host, port, sessionId);
getLogcatClient().connect(URI.create(endpoint));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import io.appium.java_client.ws.StringWebSocketClient;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.function.Consumer;

import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
Expand Down Expand Up @@ -57,15 +59,13 @@ default void startSyslogBroadcast(String host) {
* @param port the port of the host where Appium server is running
*/
default void startSyslogBroadcast(String host, int port) {
RemoteWebDriver remoteWebDriver = (RemoteWebDriver) this;
URL serverUrl = ((HttpCommandExecutor) remoteWebDriver.getCommandExecutor()).getAddressOfRemoteServer();
String scheme = "https".equals(serverUrl.getProtocol()) ? "wss" : "ws";
CommandExecutionHelper.executeScript(this, "mobile: startLogsBroadcast");
final URI endpointUri;
try {
endpointUri = new URI(String.format("ws://%s:%s/ws/session/%s/appium/device/syslog",
host, port, ((RemoteWebDriver) this).getSessionId()));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
getSyslogClient().connect(endpointUri);
SessionId sessionId = remoteWebDriver.getSessionId();
String endpoint = String.format("%s://%s:%s/ws/session/%s/appium/device/syslog", scheme, host, port, sessionId);
getSyslogClient().connect(URI.create(endpoint));
}

/**
Expand Down

0 comments on commit 5d4062a

Please sign in to comment.