-
-
Notifications
You must be signed in to change notification settings - Fork 766
Description
Hi appium team!
I was experimenting with selenium's WebDriverDecorator (to decorate WebElement that auto-waits for conditions like clickable&editable&non-readOnly etc), but found out that pure selenium's WebDriverDecorator does not work with AppiumFieldDecorator. I believe this is because WebDriverDecorator creates proxy for WebElement , but AppiumFieldDecorator uses proxies for RemoteWebElement which makes invoking the original element's methods failing. Here is the code to reproduce the exception:
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
// other imports
class SeleniumDecoratorTest {
@Test
void seleniumDecoratorDecorates() {
WebDriver originalDriver = mock(WebDriver.class);
WebElement originalWebElement = mock(WebElement.class);
when(originalDriver.findElement(any())).thenReturn(originalWebElement);
WebDriver decoratedWebDriver = new EventFiringDecorator<>().decorate(originalDriver); // do-nothing decorator, but creates selenium's WebElement decorator/proxy : https://github.com/SeleniumHQ/selenium/blob/1c58e5028bc5eaa94b12b856c2d4a87efa5363f5/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java#L331
MobilePageObject mobilePageObject = new MobilePageObject();
PageFactory.initElements(new AppiumFieldDecorator(decoratedWebDriver), mobilePageObject);
mobilePageObject.element.click(); // this fails. likely because the underlying object is expected to be RemoteWebElement: https://github.com/appium/java-client/blob/0b4a430f8e76f48ba166c77a35ab2bd696620741/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java#L258
verify(originalWebElement).click(); // verify that the original WebElement was clicked
}
static class MobilePageObject {
@AndroidFindBy(id = "some_id")
WebElement element;
}
}Exception stacktrace is:
object is not an instance of declaring class
java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.checkReceiver(DirectMethodHandleAccessor.java:197)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:99)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at io.appium.java_client.pagefactory.ElementInterceptor.getObject(ElementInterceptor.java:42)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.call(InterceptorOfASingleElement.java:78)
at io.appium.java_client.proxy.Interceptor.intercept(Interceptor.java:78)
at org.openqa.selenium.remote.RemoteWebElement$ByteBuddy$SGYRx3lC.click(Unknown Source)
at io.appium.java_client.pagefactory_tests.SeleniumDecoratorTest.seleniumDecoratorDecorates(SeleniumDecoratorTest.java:27)versions info : appium-java v10.0.0, (no appium server used - mocked drivers only)
Question: (assuming mismatch of WebElement and RemoteWebElement proxies causes this issue) What is the reason Appium uses RemoteWebElement proxy and not WebElement? I need some hints to understand if using selenium's decorator still possible in theory or not.
Thanks!