Skip to content

Commit 458259f

Browse files
committed
Address comments
1 parent 2b93de8 commit 458259f

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

src/main/java/io/appium/java_client/proxy/RemoteWebElementListener.java renamed to src/main/java/io/appium/java_client/proxy/WebDriverListener.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package io.appium.java_client.proxy;
1818

19-
import com.google.common.base.Preconditions;
2019
import net.bytebuddy.matcher.ElementMatchers;
2120
import org.openqa.selenium.WebDriver;
2221
import org.openqa.selenium.remote.RemoteWebDriver;
2322
import org.openqa.selenium.remote.RemoteWebElement;
2423

2524
import java.lang.reflect.Method;
26-
import java.util.Collection;
2725
import java.util.Collections;
2826
import java.util.List;
2927
import java.util.concurrent.Callable;
@@ -33,22 +31,14 @@
3331
import static io.appium.java_client.proxy.Helpers.createProxy;
3432
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
3533

36-
public class RemoteWebElementListener implements MethodCallListener, ProxyAwareListener {
34+
public class WebDriverListener implements MethodCallListener, ProxyAwareListener {
3735
private WebDriver parent;
38-
private final Collection<MethodCallListener> listeners;
39-
40-
public RemoteWebElementListener(MethodCallListener listener) {
41-
this.listeners = Collections.singletonList(listener);
42-
}
43-
44-
public RemoteWebElementListener(Collection<MethodCallListener> listeners) {
45-
this.listeners = listeners;
46-
}
4736

4837
@Override
4938
public void attachProxyInstance(Object proxy) {
50-
Preconditions.checkArgument(proxy instanceof WebDriver);
51-
this.parent = (WebDriver) proxy;
39+
if (proxy instanceof WebDriver) {
40+
this.parent = (WebDriver) proxy;
41+
}
5242
}
5343

5444
@Override
@@ -59,13 +49,13 @@ public Object call(Object obj, Method method, Object[] args, Callable<?> origina
5949
return wrapElement(
6050
(RemoteWebElement) result,
6151
parent,
62-
listeners);
52+
this);
6353
}
6454

6555
if (result instanceof List) {
6656
return ((List<?>) result).stream()
6757
.map(item -> item instanceof RemoteWebElement ? wrapElement(
68-
(RemoteWebElement) item, parent, listeners) : item)
58+
(RemoteWebElement) item, parent, this) : item)
6959
.collect(Collectors.toList());
7060
}
7161

@@ -75,13 +65,13 @@ public Object call(Object obj, Method method, Object[] args, Callable<?> origina
7565
private RemoteWebElement wrapElement(
7666
RemoteWebElement original,
7767
WebDriver parent,
78-
Collection<MethodCallListener> listeners
68+
MethodCallListener listener
7969
) {
8070
RemoteWebElement proxy = createProxy(
8171
RemoteWebElement.class,
8272
new Object[]{},
8373
new Class[]{},
84-
listeners,
74+
Collections.singletonList(listener),
8575
ElementMatchers.not(
8676
namedOneOf(
8777
OBJECT_METHOD_NAMES.toArray(new String[0]))

src/test/java/io/appium/java_client/proxy/ProxyHelpersTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,21 @@ public Object onError(Object obj, Method method, Object[] args, Throwable e) thr
167167

168168

169169
@Test
170-
void shouldFireEventsForRemoteWebElement() throws MalformedURLException {
170+
void shouldFireEventsForAllWebDriverCommands() throws MalformedURLException {
171171
final StringBuilder acc = new StringBuilder();
172-
MethodCallListener listener = new MethodCallListener() {
172+
173+
WebDriverListener remoteWebElementListener = new WebDriverListener() {
173174
@Override
174175
public void beforeCall(Object target, Method method, Object[] args) {
175176
acc.append("beforeCall ").append(method.getName()).append("\n");
176177
}
177178
};
178179

179-
RemoteWebElementListener remoteWebElementListener = new RemoteWebElementListener(listener);
180-
181180
FakeIOSDriver driver = createProxy(
182181
FakeIOSDriver.class,
183182
new Object[] {new URL("http://localhost:4723/"), new XCUITestOptions()},
184183
new Class[] {URL.class, Capabilities.class},
185-
List.of(remoteWebElementListener, listener)
184+
remoteWebElementListener
186185
);
187186

188187
WebElement element = driver.findElement(By.id("button"));

0 commit comments

Comments
 (0)