20
20
import io .appium .java_client .ExecutesMethod ;
21
21
import io .appium .java_client .ws .StringWebSocketClient ;
22
22
import org .openqa .selenium .remote .RemoteWebDriver ;
23
+ import org .openqa .selenium .remote .SessionId ;
23
24
24
25
import java .net .URI ;
25
- import java .net .URISyntaxException ;
26
26
import java .util .function .Consumer ;
27
27
28
28
import static io .appium .java_client .service .local .AppiumServiceBuilder .DEFAULT_APPIUM_PORT ;
@@ -36,7 +36,7 @@ public interface ListensToLogcatMessages extends ExecutesMethod {
36
36
* is assigned to the default port (4723).
37
37
*/
38
38
default void startLogcatBroadcast () {
39
- startLogcatBroadcast ("127.0.0.1" , DEFAULT_APPIUM_PORT );
39
+ startLogcatBroadcast ("127.0.0.1" );
40
40
}
41
41
42
42
/**
@@ -49,21 +49,42 @@ default void startLogcatBroadcast(String host) {
49
49
startLogcatBroadcast (host , DEFAULT_APPIUM_PORT );
50
50
}
51
51
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
+
52
64
/**
53
65
* Start logcat messages broadcast via web socket.
54
66
*
55
67
* @param host the name of the host where Appium server is running
56
68
* @param port the port of the host where Appium server is running
57
69
*/
58
70
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 ) {
59
83
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 ));
67
88
getLogcatClient ().connect (endpointUri );
68
89
}
69
90
0 commit comments