How to use AppiumWebDriverEventListener class of io.appium.java_client.events.api.general package

Best io.appium code snippet using io.appium.java_client.events.api.general.AppiumWebDriverEventListener

Run io.appium automation tests on LambdaTest cloud grid

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

DefaultListener.java

Source: DefaultListener.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.events;
18
19import io.appium.java_client.events.api.Listener;
20import io.appium.java_client.events.api.general.AlertEventListener;
21import io.appium.java_client.events.api.general.AppiumWebDriverEventListener;
22import io.appium.java_client.events.api.general.ElementEventListener;
23import io.appium.java_client.events.api.general.JavaScriptEventListener;
24import io.appium.java_client.events.api.general.ListensToException;
25import io.appium.java_client.events.api.general.NavigationEventListener;
26import io.appium.java_client.events.api.general.SearchingEventListener;
27import io.appium.java_client.events.api.general.WindowEventListener;
28import io.appium.java_client.events.api.mobile.ContextEventListener;
29import io.appium.java_client.events.api.mobile.RotationEventListener;
30import org.openqa.selenium.Alert;
31import org.openqa.selenium.By;
32import org.openqa.selenium.Dimension;
33import org.openqa.selenium.Point;
34import org.openqa.selenium.ScreenOrientation;
35import org.openqa.selenium.WebDriver;
36import org.openqa.selenium.WebElement;
37import org.openqa.selenium.security.Credentials;
38import org.openqa.selenium.support.events.WebDriverEventListener;
39
40import java.lang.reflect.Proxy;
41import java.util.ArrayList;
42import java.util.Collection;
43import java.util.List;
44
45class DefaultListener
46    implements Listener, AppiumWebDriverEventListener, ListensToException, SearchingEventListener,
47    NavigationEventListener, JavaScriptEventListener, ElementEventListener, AlertEventListener,
48    WindowEventListener, ContextEventListener, RotationEventListener {
49
50    private final List<Listener> listeners = new ArrayList<>();
51
52    private Object dispatcher = Proxy.newProxyInstance(Listener.class.getClassLoader(),
53        new Class[] {AlertEventListener.class, ContextEventListener.class,
54            ElementEventListener.class, JavaScriptEventListener.class, ListensToException.class,
55            NavigationEventListener.class, RotationEventListener.class,
56            SearchingEventListener.class, WindowEventListener.class, WebDriverEventListener.class},
57        new ListenerInvocationHandler(listeners));
58
59    @Override public void beforeNavigateTo(String url, WebDriver driver) {
60        ((NavigationEventListener) dispatcher).beforeNavigateTo(url, driver);
61    }
62
63    @Override public void afterNavigateTo(String url, WebDriver driver) {
64        ((NavigationEventListener) dispatcher).afterNavigateTo(url, driver);
65    }
66
67    @Override public void beforeNavigateBack(WebDriver driver) {
68        ((NavigationEventListener) dispatcher).beforeNavigateBack(driver);
69    }
70
71    @Override public void afterNavigateBack(WebDriver driver) {
72        ((NavigationEventListener) dispatcher).afterNavigateBack(driver);
73    }
74
75    @Override public void beforeNavigateForward(WebDriver driver) {
76        ((NavigationEventListener) dispatcher).beforeNavigateForward(driver);
77    }
78
79    @Override public void afterNavigateForward(WebDriver driver) {
80        ((NavigationEventListener) dispatcher).afterNavigateForward(driver);
81    }
82
83    @Override public void beforeNavigateRefresh(WebDriver driver) {
84        ((NavigationEventListener) dispatcher).beforeNavigateRefresh(driver);
85    }
86
87    @Override public void afterNavigateRefresh(WebDriver driver) {
88        ((NavigationEventListener) dispatcher).afterNavigateRefresh(driver);
89    }
90
91    @Override public void beforeFindBy(By by, WebElement element, WebDriver driver) {
92        ((SearchingEventListener) dispatcher).beforeFindBy(by, element, driver);
93    }
94
95    @Override public void afterFindBy(By by, WebElement element, WebDriver driver) {
96        ((SearchingEventListener) dispatcher).afterFindBy(by, element, driver);
97    }
98
99    @Override public void beforeClickOn(WebElement element, WebDriver driver) {
100        ((ElementEventListener) dispatcher).beforeClickOn(element, driver);
101    }
102
103    @Override public void afterClickOn(WebElement element, WebDriver driver) {
104        ((ElementEventListener) dispatcher).afterClickOn(element, driver);
105    }
106
107    @Override public void beforeChangeValueOf(WebElement element, WebDriver driver) {
108        ((ElementEventListener) dispatcher).beforeChangeValueOf(element, driver);
109    }
110
111    @Override public void beforeChangeValueOf(WebElement element, WebDriver driver,
112        CharSequence[] keysToSend) {
113        ((ElementEventListener) dispatcher).beforeChangeValueOf(element, driver, keysToSend);
114    }
115
116    @Override public void afterChangeValueOf(WebElement element, WebDriver driver) {
117        ((ElementEventListener) dispatcher).afterChangeValueOf(element, driver);
118    }
119
120    @Override public void afterChangeValueOf(WebElement element, WebDriver driver,
121        CharSequence[] keysToSend) {
122        ((ElementEventListener) dispatcher).afterChangeValueOf(element, driver, keysToSend);
123    }
124
125    @Override public void beforeScript(String script, WebDriver driver) {
126        ((JavaScriptEventListener) dispatcher).beforeScript(script, driver);
127    }
128
129    @Override public void afterScript(String script, WebDriver driver) {
130        ((JavaScriptEventListener) dispatcher).afterScript(script, driver);
131    }
132
133    @Override public void onException(Throwable throwable, WebDriver driver) {
134        ((ListensToException) dispatcher).onException(throwable, driver);
135    }
136
137    public void add(Collection<Listener> listeners) {
138        this.listeners.addAll(listeners);
139    }
140
141    @Override public void beforeAlertAccept(WebDriver driver, Alert alert) {
142        ((AlertEventListener) dispatcher).beforeAlertAccept(driver, alert);
143    }
144
145    @Override
146    public void beforeAlertAccept(WebDriver driver) {
147        ((WebDriverEventListener) dispatcher).beforeAlertAccept(driver);
148    }
149
150    @Override public void afterAlertAccept(WebDriver driver, Alert alert) {
151        ((AlertEventListener) dispatcher).afterAlertAccept(driver, alert);
152    }
153
154    @Override
155    public void afterAlertAccept(WebDriver driver) {
156        ((WebDriverEventListener) dispatcher).afterAlertAccept(driver);
157    }
158
159    @Override public void afterAlertDismiss(WebDriver driver, Alert alert) {
160        ((AlertEventListener) dispatcher).afterAlertDismiss(driver, alert);
161    }
162
163    @Override
164    public void afterAlertDismiss(WebDriver driver) {
165        ((WebDriverEventListener) dispatcher).afterAlertDismiss(driver);
166    }
167
168    @Override public void beforeAlertDismiss(WebDriver driver, Alert alert) {
169        ((AlertEventListener) dispatcher).beforeAlertDismiss(driver, alert);
170    }
171
172    @Override
173    public void beforeAlertDismiss(WebDriver driver) {
174        ((WebDriverEventListener) dispatcher).beforeAlertDismiss(driver);
175    }
176
177    @Override public void beforeAlertSendKeys(WebDriver driver, Alert alert, String keys) {
178        ((AlertEventListener) dispatcher).beforeAlertSendKeys(driver, alert, keys);
179    }
180
181    @Override public void afterAlertSendKeys(WebDriver driver, Alert alert, String keys) {
182        ((AlertEventListener) dispatcher).afterAlertSendKeys(driver, alert, keys);
183    }
184
185    @Override
186    public void beforeAuthentication(WebDriver driver, Alert alert, Credentials credentials) {
187        ((AlertEventListener) dispatcher).beforeAuthentication(driver, alert, credentials);
188    }
189
190    @Override
191    public void afterAuthentication(WebDriver driver, Alert alert, Credentials credentials) {
192        ((AlertEventListener) dispatcher).afterAuthentication(driver, alert, credentials);
193    }
194
195    @Override public void beforeWindowChangeSize(WebDriver driver, WebDriver.Window window,
196        Dimension targetSize) {
197        ((WindowEventListener) dispatcher).beforeWindowChangeSize(driver, window, targetSize);
198    }
199
200    @Override public void afterWindowChangeSize(WebDriver driver, WebDriver.Window window,
201        Dimension targetSize) {
202        ((WindowEventListener) dispatcher).afterWindowChangeSize(driver, window, targetSize);
203    }
204
205    @Override
206    public void beforeWindowIsMoved(WebDriver driver, WebDriver.Window window, Point targetPoint) {
207        ((WindowEventListener) dispatcher).beforeWindowIsMoved(driver, window, targetPoint);
208    }
209
210    @Override
211    public void afterWindowIsMoved(WebDriver driver, WebDriver.Window window, Point targetPoint) {
212        ((WindowEventListener) dispatcher).afterWindowIsMoved(driver, window, targetPoint);
213    }
214
215    @Override public void beforeWindowIsMaximized(WebDriver driver, WebDriver.Window window) {
216        ((WindowEventListener) dispatcher).beforeWindowIsMaximized(driver, window);
217    }
218
219    @Override public void afterWindowIsMaximized(WebDriver driver, WebDriver.Window window) {
220        ((WindowEventListener) dispatcher).afterWindowIsMaximized(driver, window);
221    }
222
223    @Override public void beforeSwitchingToContext(WebDriver driver, String context) {
224        ((ContextEventListener) dispatcher).beforeSwitchingToContext(driver, context);
225    }
226
227    @Override public void afterSwitchingToContext(WebDriver driver, String context) {
228        ((ContextEventListener) dispatcher).afterSwitchingToContext(driver, context);
229    }
230
231    @Override public void beforeRotation(WebDriver driver, ScreenOrientation orientation) {
232        ((RotationEventListener) dispatcher).beforeRotation(driver, orientation);
233    }
234
235    @Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) {
236        ((RotationEventListener) dispatcher).afterRotation(driver, orientation);
237    }
238}
Full Screen

AppiumListener.java

Source: AppiumListener.java Github

copy
1package com.telran.fw;
2
3import io.appium.java_client.AppiumDriver;
4import io.appium.java_client.events.api.general.AppiumWebDriverEventListener;
5import org.openqa.selenium.By;
6import org.openqa.selenium.OutputType;
7import org.openqa.selenium.WebDriver;
8import org.openqa.selenium.WebElement;
9import org.slf4j.LoggerFactory;
10import org.slf4j.Logger;
11
12
13
14public class AppiumListener implements AppiumWebDriverEventListener {
15    Logger logger = LoggerFactory.getLogger(AppiumListener.class);
16
17
18    @Override
19    public void beforeChangeValueOf(WebElement element, WebDriver driver) {
20
21    }
22
23    @Override
24    public void afterChangeValueOf(WebElement element, WebDriver driver) {
25
26    }
27
28    @Override
29    public void beforeAlertAccept(WebDriver driver) {
30
31    }
32
33    @Override
34    public void afterAlertAccept(WebDriver driver) {
35
36    }
37
38    @Override
39    public void afterAlertDismiss(WebDriver driver) {
40
41    }
42
43    @Override
44    public void beforeAlertDismiss(WebDriver driver) {
45
46    }
47
48    @Override
49    public void beforeNavigateTo(String url, WebDriver driver) {
50
51    }
52
53    @Override
54    public void afterNavigateTo(String url, WebDriver driver) {
55
56    }
57
58    @Override
59    public void beforeNavigateBack(WebDriver driver) {
60
61    }
62
63    @Override
64    public void afterNavigateBack(WebDriver driver) {
65
66    }
67
68    @Override
69    public void beforeNavigateForward(WebDriver driver) {
70
71    }
72
73    @Override
74    public void afterNavigateForward(WebDriver driver) {
75
76    }
77
78    @Override
79    public void beforeNavigateRefresh(WebDriver driver) {
80
81    }
82
83    @Override
84    public void afterNavigateRefresh(WebDriver driver) {
85
86    }
87
88    @Override
89    public void beforeFindBy(By by, WebElement element, WebDriver driver) {
90        logger.info("Start find -->" + by);
91    }
92
93    @Override
94    public void afterFindBy(By by, WebElement element, WebDriver driver) {
95
96        logger.info(by + "<-- Found");
97    }
98
99    @Override
100    public void beforeClickOn(WebElement element, WebDriver driver) {
101
102    }
103
104    @Override
105    public void afterClickOn(WebElement element, WebDriver driver) {
106
107    }
108
109    @Override
110    public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
111
112    }
113
114    @Override
115    public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
116
117    }
118
119    @Override
120    public void beforeScript(String script, WebDriver driver) {
121
122    }
123
124    @Override
125    public void afterScript(String script, WebDriver driver) {
126
127    }
128
129    @Override
130    public void beforeSwitchToWindow(String windowName, WebDriver driver) {
131
132    }
133
134    @Override
135    public void afterSwitchToWindow(String windowName, WebDriver driver) {
136
137    }
138
139    @Override
140    public void onException(Throwable throwable, WebDriver driver) {
141        logger.error(throwable.toString());
142        HelperBase helperBase = new HelperBase((AppiumDriver) driver);
143        String path = "src/test/screenshots/screen-"
144                + System.currentTimeMillis()/1000%3600 + ".png";
145    }
146
147    @Override
148    public <X> void beforeGetScreenshotAs(OutputType<X> target) {
149
150    }
151
152    @Override
153    public <X> void afterGetScreenshotAs(OutputType<X> target, X screenshot) {
154
155    }
156
157    @Override
158    public void beforeGetText(WebElement element, WebDriver driver) {
159
160    }
161
162    @Override
163    public void afterGetText(WebElement element, WebDriver driver, String text) {
164
165    }
166}
167
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

Most used methods in AppiumWebDriverEventListener

    No methods found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)