Skip to content

Commit 107b41b

Browse files
committed
#16573 unwrap double-wrapped webdriver
1 parent d3a2670 commit 107b41b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,15 @@ protected static class Definition {
195195

196196
public Definition(Decorated<?> decorated) {
197197
this.decoratedClass = decorated.getClass();
198-
this.originalClass = decorated.getOriginal().getClass();
198+
this.originalClass = unwrapOriginal(decorated).getClass();
199+
}
200+
201+
private static Object unwrapOriginal(Decorated<?> decorated) {
202+
Object original = decorated.getOriginal();
203+
while (original instanceof WrapsDriver) {
204+
original = ((WrapsDriver) original).getWrappedDriver();
205+
}
206+
return original;
199207
}
200208

201209
@Override
@@ -480,12 +488,12 @@ private static void extractInterfaces(final Set<Class<?>> collector, final Class
480488
private <Z> Map<Class<?>, Function<Z, InvocationHandler>> deriveAdditionalInterfaces(Z sample) {
481489
Map<Class<?>, Function<Z, InvocationHandler>> handlers = new HashMap<>();
482490

483-
if (sample instanceof WebDriver && !(sample instanceof WrapsDriver)) {
491+
if (sample instanceof WebDriver) {
484492
handlers.put(
485493
WrapsDriver.class,
486494
(instance) ->
487495
(proxy, method, args) -> {
488-
if ("getWrappedDriver".equals(method.getName())) {
496+
if (sample instanceof WrapsDriver || "getWrappedDriver".equals(method.getName())) {
489497
return instance;
490498
}
491499
throw new UnsupportedOperationException(method.getName());

0 commit comments

Comments
 (0)