Skip to content

Commit c262974

Browse files
committed
Update the docs - The-event_firing.md
1 parent f379757 commit c262974

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/The-event_firing.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,60 @@ This proxy is not tied to WebDriver descendants and could be used to any classes
154154
change/replace the original methods behavior. It is important to know that callbacks are **not** invoked
155155
for methods derived from the standard `Object` class, like `toString` or `equals`.
156156
Check [unit tests](../src/test/java/io/appium/java_client/proxy/ProxyHelpersTest.java) for more examples.
157+
158+
#### ElementAwareWebDriverListener
159+
160+
A specialized MethodCallListener that listens to all method calls on a WebDriver instance and automatically wraps any returned RemoteWebElement (or list of elements) with a proxy. This enables your listener to intercept and react to method calls on both:
161+
162+
- The driver itself (e.g., findElement, getTitle)
163+
164+
- Any elements returned by the driver (e.g., click, isSelected on a WebElement)
165+
166+
```java
167+
import io.appium.java_client.ios.IOSDriver;
168+
import io.appium.java_client.ios.options.XCUITestOptions;
169+
import io.appium.java_client.proxy.ElementAwareWebDriverListener;
170+
import io.appium.java_client.proxy.Helpers;
171+
import io.appium.java_client.proxy.MethodCallListener;
172+
173+
174+
// ...
175+
176+
final StringBuilder acc = new StringBuilder();
177+
178+
var listener = new ElementAwareWebDriverListener() {
179+
@Override
180+
public void beforeCall(Object target, Method method, Object[] args) {
181+
acc.append("beforeCall ").append(method.getName()).append("\n");
182+
}
183+
};
184+
185+
IOSDriver<?> decoratedDriver = createProxy(
186+
IOSDriver.class,
187+
new Object[]{new URL("http://localhost:4723/"), new XCUITestOptions()},
188+
new Class[]{URL.class, Capabilities.class},
189+
listener
190+
);
191+
192+
WebElement element = decoratedDriver.findElement(By.id("button"));
193+
element::click;
194+
195+
List<WebElement> elements = decoratedDriver.findElements(By.id("button"));
196+
elements.get(1).isSelected();
197+
198+
assertThat(acc.toString().trim()).isEqualTo(
199+
String.join("\n",
200+
"beforeCall findElement",
201+
"beforeCall click",
202+
"beforeCall getSessionId",
203+
"beforeCall getCapabilities",
204+
"beforeCall getCapabilities",
205+
"beforeCall findElements",
206+
"beforeCall isSelected",
207+
"beforeCall getSessionId",
208+
"beforeCall getCapabilities",
209+
"beforeCall getCapabilities"
210+
)
211+
);
212+
213+
```

0 commit comments

Comments
 (0)