19
19
import io .appium .java_client .CommandExecutionHelper ;
20
20
import io .appium .java_client .ExecutesMethod ;
21
21
import io .appium .java_client .ws .StringWebSocketClient ;
22
+ import org .openqa .selenium .remote .HttpCommandExecutor ;
22
23
import org .openqa .selenium .remote .RemoteWebDriver ;
24
+ import org .openqa .selenium .remote .SessionId ;
23
25
24
26
import java .net .URI ;
25
- import java .net .URISyntaxException ;
27
+ import java .net .URL ;
26
28
import java .util .function .Consumer ;
27
29
28
30
import static io .appium .java_client .service .local .AppiumServiceBuilder .DEFAULT_APPIUM_PORT ;
@@ -36,7 +38,7 @@ public interface ListensToLogcatMessages extends ExecutesMethod {
36
38
* is assigned to the default port (4723).
37
39
*/
38
40
default void startLogcatBroadcast () {
39
- startLogcatBroadcast ("127.0.0.1" , DEFAULT_APPIUM_PORT );
41
+ startLogcatBroadcast ("127.0.0.1" );
40
42
}
41
43
42
44
/**
@@ -56,15 +58,13 @@ default void startLogcatBroadcast(String host) {
56
58
* @param port the port of the host where Appium server is running
57
59
*/
58
60
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" ;
59
64
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 ));
68
68
}
69
69
70
70
/**
0 commit comments