clarification request: pure selenium's WebDriverDecorator doesn't work with AppiumFieldDecorator - is RemoteWebElement the issue?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先从可复现的 SeleniumDecoratorTest 示例开始,然后阅读 AppiumFieldDecorator.java 中所引用的代理处理部分,以及堆栈跟踪中的 ElementInterceptor.java。比较 WebElement 和 RemoteWebElement 的代理假设,并确定是否能够实现兼容;只有通过测试或有文档记录的结论确立了预期行为和任何必要的变更后,该 issue 才算完成。
由索引模型根据 Issue 内容生成。
描述
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!
- 主要语言
- Java
- 星标
- 1.3k
- 派生
- 755
- 平均合并
- 5 天 14 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
appium/java-client 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
appium/java-client#2426 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 50/100
appium/java-client#2372 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 30/100
appium/java-client#2341 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 15/100
appium/java-client#2323 ·
维护者通常 1 天内回复
-
java-client 启动报错未关闭
难度 3/5 1-2 天 新手友好度 35/100
appium/java-client#2288 · 1 条评论 ·
维护者通常 1 天内回复
查看 appium/java-client 的全部 Issue
相似的 Issue
-
P2 testing
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
area/core kind/bug status/triage team/core-shared
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
checkstyle/checkstyle#21755 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
spring-projects/spring-integration#11495 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复