How to use getSyslogClient method of io.appium.java_client.ios.ListensToSyslogMessages class

Best io.appium code snippet using io.appium.java_client.ios.ListensToSyslogMessages.getSyslogClient

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ListensToSyslogMessages.java

Source: ListensToSyslogMessages.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.ios;
18
19import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
20import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;
21
22import com.google.common.collect.ImmutableMap;
23
24import io.appium.java_client.ExecutesMethod;
25import io.appium.java_client.ws.StringWebSocketClient;
26import org.openqa.selenium.remote.RemoteWebDriver;
27
28import java.net.URI;
29import java.net.URISyntaxException;
30import java.util.Collections;
31import java.util.function.Consumer;
32
33public interface ListensToSyslogMessages extends ExecutesMethod {
34
35    StringWebSocketClient getSyslogClient();
36
37    /**
38     * Start syslog messages broadcast via web socket.
39     * This method assumes that Appium server is running on localhost and
40     * is assigned to the default port (4723).
41     */
42    default void startSyslogBroadcast() {
43        startSyslogBroadcast("localhost", DEFAULT_APPIUM_PORT);
44    }
45
46    /**
47     * Start syslog messages broadcast via web socket.
48     * This method assumes that Appium server is assigned to the default port (4723).
49     *
50     * @param host the name of the host where Appium server is running
51     */
52    default void startSyslogBroadcast(String host) {
53        startSyslogBroadcast(host, DEFAULT_APPIUM_PORT);
54    }
55
56    /**
57     * Start syslog messages broadcast via web socket.
58     *
59     * @param host the name of the host where Appium server is running
60     * @param port the port of the host where Appium server is running
61     */
62    default void startSyslogBroadcast(String host, int port) {
63        execute(EXECUTE_SCRIPT, ImmutableMap.of("script", "mobile: startLogsBroadcast",
64                "args", Collections.emptyList()));
65        final URI endpointUri;
66        try {
67            endpointUri = new URI(String.format("ws://%s:%s/ws/session/%s/appium/device/syslog",
68                    host, port, ((RemoteWebDriver) this).getSessionId()));
69        } catch (URISyntaxException e) {
70            throw new IllegalArgumentException(e);
71        }
72        getSyslogClient().connect(endpointUri);
73    }
74
75    /**
76     * Adds a new log messages broadcasting handler.
77     * Several handlers might be assigned to a single server.
78     * Multiple calls to this method will cause such handler
79     * to be called multiple times.
80     *
81     * @param handler a function, which accepts a single argument, which is the actual log message
82     */
83    default void addSyslogMessagesListener(Consumer<String> handler) {
84        getSyslogClient().addMessageHandler(handler);
85    }
86
87    /**
88     * Adds a new log broadcasting errors handler.
89     * Several handlers might be assigned to a single server.
90     * Multiple calls to this method will cause such handler
91     * to be called multiple times.
92     *
93     * @param handler a function, which accepts a single argument, which is the actual exception instance
94     */
95    default void addSyslogErrorsListener(Consumer<Throwable> handler) {
96        getSyslogClient().addErrorHandler(handler);
97    }
98
99    /**
100     * Adds a new log broadcasting connection handler.
101     * Several handlers might be assigned to a single server.
102     * Multiple calls to this method will cause such handler
103     * to be called multiple times.
104     *
105     * @param handler a function, which is executed as soon as the client is successfully
106     *                connected to the web socket
107     */
108    default void addSyslogConnectionListener(Runnable handler) {
109        getSyslogClient().addConnectionHandler(handler);
110    }
111
112    /**
113     * Adds a new log broadcasting disconnection handler.
114     * Several handlers might be assigned to a single server.
115     * Multiple calls to this method will cause such handler
116     * to be called multiple times.
117     *
118     * @param handler a function, which is executed as soon as the client is successfully
119     *                disconnected from the web socket
120     */
121    default void addSyslogDisconnectionListener(Runnable handler) {
122        getSyslogClient().addDisconnectionHandler(handler);
123    }
124
125    /**
126     * Removes all existing syslog handlers.
127     */
128    default void removeAllSyslogListeners() {
129        getSyslogClient().removeAllHandlers();
130    }
131
132    /**
133     * Stops syslog messages broadcast via web socket.
134     */
135    default void stopSyslogBroadcast() {
136        execute(EXECUTE_SCRIPT, ImmutableMap.of("script", "mobile: stopLogsBroadcast",
137                "args", Collections.emptyList()));
138    }
139}
140
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger getSyslogClient code on LambdaTest Cloud Grid

Execute automation tests with getSyslogClient on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)