AppiumTestDistribution / appium-wait-plugin

Plugin to automatically manage all element waits and enables to write wait-free appium tests.
MIT License
59 stars 10 forks source link

Command 'findElement' was not handled by the following behaviors or plugins #119

Open dipakkumar1225 opened 3 weeks ago

dipakkumar1225 commented 3 weeks ago

Configuration

Appium 2.3.0 and Java-client 9.2.3

Driver Used

plugin used

The element-wait plugin conflicts with the images plugin. After removing the element-wait plugin from the --use-plugins list, the image element is clicked properly.

[AppiumDriver@48ff] Command 'findElement' was not handled by the following behaviours or plugins, even though they were registered to handle it: ["default","images","ocr"]. The command was handled by these: ["element-wait"].

public class Main {

    private static AppiumDriverLocalService getAppiumDriverService() {
        String strDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMMM_dd_yyyy"));
        String strTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH_mm_ss"));
        var strReportDir = Paths.get(System.getProperty("user.dir"), strDate);

        String logFileName = String.format("Appium_Server_%s.log", strTime);
        File logFile = new File(Paths.get(strReportDir.toString(), logFileName).toString());

        return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                .withIPAddress("127.0.0.1")
                .usingPort(4723)
                .withArgument(() -> "--long-stacktrace")
                .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
                .withArgument(GeneralServerFlag.USE_DRIVERS, "uiautomator2")
                .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
                .withArgument(GeneralServerFlag.RELAXED_SECURITY)
                .withArgument(GeneralServerFlag.USE_PLUGINS, "images, gestures, ocr")//element-wait
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withArgument(() -> "--config", new File(System.getProperty("user.dir") + File.separator + "config" + File.separator + "serverconfig.json").toString())
                .withTimeout(Duration.ofSeconds(240))
                .withLogOutput(System.err)
                .withLogFile(logFile));
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        AppiumDriverLocalService appiumDriverLocalService = getAppiumDriverService();
        AppiumDriver appiumDriver = null;
        try {
            appiumDriverLocalService.start();

            UiAutomator2Options uiAutomator2Options = new UiAutomator2Options()
                    .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
                    .setApp(System.getProperty("user.dir") + File.separator + "app" + File.separator + "android" + File.separator + "mda-2.0.2-23.apk")
                    .setFullReset(false)
                    .setNoReset(true)
                    .setPlatformName("android")
                    .setPlatformVersion("13")
                    .setUdid("ZD222CJSXB")
                    .setAppPackage("com.saucelabs.mydemoapp.android")
                    .setAppActivity("com.saucelabs.mydemoapp.android.view.activities.SplashActivity");

            uiAutomator2Options.setCapability("shouldTerminateApp", true);

            System.out.println("URL " + appiumDriverLocalService.getUrl());
            appiumDriver = new AndroidDriver(appiumDriverLocalService.getUrl(), uiAutomator2Options);
            System.out.println("SessionID " + appiumDriver.getSessionId());

            Thread.sleep(5000);

            byte[] navMenuByte = FileUtils.readFileToByteArray(new File(System.getProperty("user.dir") + File.separator + "image" + File.separator + "NavMenuIcon.png"));
            String navMenuEncodedString = Base64.getEncoder().encodeToString(navMenuByte);

            appiumDriver.findElement(AppiumBy.image(navMenuEncodedString)).click();

            Thread.sleep(5000);

        } finally {
            if (appiumDriver != null) {
                appiumDriver.quit();
            }
            appiumDriverLocalService.stop();
        }
    }
}
  1. Failed Log when element-wait is passed in --use-plugins Command 'findElement' was not handled by the following behaviours or plugins, even though they were registered to handle it: ["default","images","ocr"]. The command was handled by these: ["element-wait"]

https://gist.github.com/dipakkumar1225/207e6ce236f3f6bb27abfcfe6ca7ac1f

  1. Success Log when element-wait plugin is not used in --use-plugins https://gist.github.com/dipakkumar1225/c80de443415e7f15fa486cce78d94e08

Sample App https://github.com/dipakkumar1225/AppiumWaitPluginSample

Please suggest the solution for this

dipakkumar1225 commented 3 weeks ago

any solution