appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.21k stars 756 forks source link

Unexpected Selector Translation with @AndroidFindBy and AppiumFieldDecorator #2051

Open dipakkumar1225 opened 11 months ago

dipakkumar1225 commented 11 months ago

Description

I've encountered an unexpected behavior when using @AndroidFindBy annotation in conjunction with PageFactory.initElements(new AppiumFieldDecorator(eventDriver, Duration.ofSeconds(30)), this);.

Environment

Details

When using the annotation @AndroidFindBy(accessibility = "open menu") for an element, I'm encountering an error stating:

Unsupported CSS selector '*[name='webElementOpenMenu']'. Reason: ''name' is not a valid attribute. Supported attributes are 'checkable, checked, clickable, enabled, focusable, focused, long-clickable, scrollable, selected, index, instance, description, resource-id, text, class-name, package-name''

However, using the direct method appiumDriver.findElementByAccessibilityId("open menu").click(); works without any issues.

It appears that the accessibility attribute from the annotation is being incorrectly translated into a CSS selector with the name attribute when using AppiumFieldDecorator with EventFiringWebDriver.

Code To Reproduce Issue [ Good To Have ]


 @AndroidFindBy(accessibility = "open menu")
    private WebElement webElementOpenMenu;

    @Test()
    public void demaoTest() {
        AppiumDriverLocalService appiumDriverLocalService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                .withIPAddress("127.0.0.1")
                .usingPort(4723)
                .withArgument(GeneralServerFlag.RELAXED_SECURITY)
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withArgument(GeneralServerFlag.USE_DRIVERS, "uiautomator2")
                .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
                .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
                .withTimeout(Duration.ofSeconds(180)));
        appiumDriverLocalService.start();

        UiAutomator2Options uiAutomator2Options = new UiAutomator2Options()
                .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
                .setApp(System.getProperty("user.dir" + File.separator + "app" + File.separator + "android" + File.separator + "Android-MyDemoAppRN.1.3.0.build-244.apk"))
                .setFullReset(false)
                .setNoReset(true)
                .setPlatformName("android")
                .setPlatformVersion("13")
                .setUdid("ZD222CJSXB")
                .setAppPackage("com.saucelabs.mydemoapp.rn")
                .setAppActivity("com.saucelabs.mydemoapp.rn.MainActivity");

        AppiumDriver appiumDriver = new AndroidDriver(appiumDriverLocalService.getUrl(), uiAutomator2Options);

        EventFiringWebDriver eventDriver = new EventFiringWebDriver(appiumDriver);
        CustomEventListener listener = new CustomEventListener();
        eventDriver.register(listener);

        //WebElement webElementOpenMenu_1 = eventDriver.findElement(AppiumBy.accessibilityId("open menu")); --- This is working

        PageFactory.initElements(new AppiumFieldDecorator(eventDriver, Duration.ofSeconds(30)), this);

        webElementOpenMenu.click();

//        webElementOpenMenu_1.click(); --- This is working

        appiumDriver.quit();
        appiumDriverLocalService.stop();
    }

Exception Stacktraces

Appium Error Log: https://gist.github.com/dipakkumar1225/619b603dbd8f9383b442b76eab343bc5

Appium Working Log: https://gist.github.com/dipakkumar1225/d7ecf952f56ddf8a93543ae87f5667d4#file-working-txt

mykola-mokhnach commented 11 months ago

AFAIK EventFiringWebDriver is deprecated. Consider using EventFiringDecorator instead or the createProxy API

dipakkumar1225 commented 11 months ago

AFAIK EventFiringWebDriver is deprecated. Consider using EventFiringDecorator instead or the createProxy API

@mykola-mokhnach When will this fix be released?