ashwithpoojary98 / javaflutterfinder

Flutter driver with Java implementation
MIT License
11 stars 5 forks source link

Getting unknown locator everytime #9

Closed surbhi03airan closed 1 year ago

surbhi03airan commented 1 year ago

Getting this everytime [io.github.ashwith.flutter.FlutterElement@ee115f32 -> unknown locator]

My apk is in debug mode and have all the pre-requirements to automate the app. I am using appiumflutterDriver@1.14.1 and tried with appiumflutterdriver@1.14.3 which is downloaded through terminal. I have added the maven dependency in my repository and trying to automate the flutter view embedded in native apk.

Desiredcapabilities code:

DesiredCapabilities cap2 = new DesiredCapabilities();
        URL url = new URL(driverProperties.get("url").toString());
        String apkPath = "", appPackage = "";
        int IMPLICIT_WAIT = Integer.parseInt(driverProperties.getProperty("implicitlyWait"));
        if (platform.equals("android")) {
                    apkPath = System.getProperty("user.dir") + "/src/test/resources/app/"
                            + System.getProperty("apkName", driverProperties.getProperty("apkName"));
                logger.info("Setting android capablities ... ");
                String udid = System.getProperty("udid", DeviceInfoHelper.getFirstAndroidDevice().getUniqueDeviceID());
                cap2.setCapability(MobileCapabilityType.DEVICE_NAME, udid);
                cap2.setCapability(MobileCapabilityType.NO_RESET, true);
                cap2.setCapability(MobileCapabilityType.APP, apkPath);
                cap2.setCapability("appium:platformName", platform);
                cap2.setCapability("appium:automationName", "Flutter");
                cap2.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 500);
            }
            try {
                flutterDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap2);
                flutterDriver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT, TimeUnit.SECONDS);
                flutterFinder = new FlutterFinder(flutterDriver);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }`

In the test class...I am trying to use the flutterFinder:`

switchContext("FLUTTER");
        System.out.println("Context is:"+flutterDriver.getContext());
        System.out.println(flutterFinder);

//        System.out.println(flutterDriver.executeScript("flutter:getRenderTree"));
        FlutterElement elements4= flutterFinder.byText("+6 OFFERS");
        System.out.println(elements4);

I am able to see the RenderTree but not able to perform any action on the flutter widget element. Appium server got struck here :

Executing Flutter driver command 'click'
[debug] [FlutterDriver] >>> {"command":"tap","text":"+6 OFFERS","finderType":"ByText"}

Appium Logs: AppiumLogs.txt

thanks in advance!

ashwithpoojary98 commented 1 year ago

I hope u followed this below steps before running your test cases. Your Flutter app-under-test (AUT) must be compiled in debug or profile mode, because Flutter Driver does not support running in release mode.. Also, ensure that your Flutter AUT has enableFlutterDriverExtension() before runApp. Then, please make sure your app imported flutter_driver package as its devDependencies as well.

surbhi03airan commented 1 year ago

Yes, app is already in debug mode And we have added the required dev dependencies as well.

surbhi03airan commented 1 year ago

Can you please help here to debug this:

  1. Do we need flutter driver maven dependency to be added in pom.xml file or just need to download the appium-flutter-driver.
  2. if maven dependency is not required, and starting the appium with automationName as Flutter dependency---- Do we need to sync the flutter with thenative in this case? as my apk is native with embedded flutter views.
  3. Right now for me "flutter:getRenderTree" is working fine but setFrameSync() and getText, click etc is not working....what can be the reasons?
surbhi03airan commented 1 year ago

There was some issue in my apk. Connected with the develop to add the valueKey or SemanticLabel for some elements uniquely and used the function of flutter setFrameSync as false This issue is fixed and working fine now. Thanks, closing the thread :)