clarification request: pure selenium's WebDriverDecorator doesn't work with AppiumFieldDecorator - is RemoteWebElement the issue?

オープン
#2,368 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
java
領域
mobile, testing

調査の方向性

再現用の 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
フォーク
752
平均マージ
6日 21時間
マージ済み PR(30日)
8

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

appium/java-client のほかの issue

appium/java-client の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。