Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to use secure WebSocket to listen Logcat messages #2182

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
var remoteWebDriver = (RemoteWebDriver) this;
URL serverUrl = ((HttpCommandExecutor) remoteWebDriver.getCommandExecutor()).getAddressOfRemoteServer();
var 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();
var 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 All @@ -37,7 +39,7 @@ public interface ListensToSyslogMessages extends ExecutesMethod {
* is assigned to the default port (4723).
*/
default void startSyslogBroadcast() {
startSyslogBroadcast("localhost", DEFAULT_APPIUM_PORT);
startSyslogBroadcast("localhost");
}

/**
Expand All @@ -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) {
var remoteWebDriver = (RemoteWebDriver) this;
URL serverUrl = ((HttpCommandExecutor) remoteWebDriver.getCommandExecutor()).getAddressOfRemoteServer();
var 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();
var endpoint = String.format("%s://%s:%s/ws/session/%s/appium/device/syslog", scheme, host, port, sessionId);
getSyslogClient().connect(URI.create(endpoint));
}

/**
Expand Down