1919import io .appium .java_client .CommandExecutionHelper ;
2020import io .appium .java_client .ExecutesMethod ;
2121import io .appium .java_client .ws .StringWebSocketClient ;
22+ import org .openqa .selenium .remote .HttpCommandExecutor ;
2223import org .openqa .selenium .remote .RemoteWebDriver ;
24+ import org .openqa .selenium .remote .SessionId ;
2325
2426import java .net .URI ;
25- import java .net .URISyntaxException ;
27+ import java .net .URL ;
2628import java .util .function .Consumer ;
2729
2830import static io .appium .java_client .service .local .AppiumServiceBuilder .DEFAULT_APPIUM_PORT ;
@@ -36,7 +38,7 @@ public interface ListensToLogcatMessages extends ExecutesMethod {
3638 * is assigned to the default port (4723).
3739 */
3840 default void startLogcatBroadcast () {
39- startLogcatBroadcast ("127.0.0.1" , DEFAULT_APPIUM_PORT );
41+ startLogcatBroadcast ("127.0.0.1" );
4042 }
4143
4244 /**
@@ -56,15 +58,13 @@ default void startLogcatBroadcast(String host) {
5658 * @param port the port of the host where Appium server is running
5759 */
5860 default void startLogcatBroadcast (String host , int port ) {
61+ var remoteWebDriver = (RemoteWebDriver ) this ;
62+ URL serverUrl = ((HttpCommandExecutor ) remoteWebDriver .getCommandExecutor ()).getAddressOfRemoteServer ();
63+ var scheme = "https" .equals (serverUrl .getProtocol ()) ? "wss" : "ws" ;
5964 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- }
67- getLogcatClient ().connect (endpointUri );
65+ SessionId sessionId = remoteWebDriver .getSessionId ();
66+ var endpoint = String .format ("%s://%s:%s/ws/session/%s/appium/device/logcat" , scheme , host , port , sessionId );
67+ getLogcatClient ().connect (URI .create (endpoint ));
6868 }
6969
7070 /**
0 commit comments