appium-flutter-driver icon indicating copy to clipboard operation
appium-flutter-driver copied to clipboard

How to implement common finder > byIcon using java appium flutter driver?

Open Tanvi-Sawant opened this issue 3 years ago • 4 comments

How to implement common finder > byIcon using java appium flutter driver?

I added following finder in my FlutterFinder.kt file

fun byIcon(icon: IconData): FlutterElement { val f = _byIcon(icon) f.setParent(driver) f.setFileDetector(fileDetector) return f }

But it says unresolved reference for IconData and _byIcon(icon)

I want to automate datepicker widget of flutter so i need the byIcon finder implementation using java appium flutter driver. https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/date_picker_test.dart

Tanvi-Sawant avatar Jan 10 '23 06:01 Tanvi-Sawant

This driver currently depends on https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html, so maybe https://api.flutter.dev/flutter/flutter_test/CommonFinders-class.html won't work.

Potentially the flutter_test can be implemented, but I don't have knowledge about it for now.

KazuCocoa avatar Jan 10 '23 09:01 KazuCocoa

@KazuCocoa Thanks for the reply. When can I expect a resolution for this?

Tanvi-Sawant avatar Jan 12 '23 10:01 Tanvi-Sawant

I don't know. I have no much time to work on the investigation. It will be when someone helps.

KazuCocoa avatar Jan 12 '23 16:01 KazuCocoa

I'm not sure when flutter_driver team is going to implement those finders which flutter_test has. I'm surprised that only main part of those were but not all.

Theoretically it is possible to implement custom finders, but there are a lot of work. You need:

  • access to app src and imported flutter_driver (if you use enableFlutterDriverExtension() it is already imported and used) with flutter_test
  • dart dev skills

As mentioned in enableFlutterDriverExtension from flutter_driver package, you can create custom finders with some examples:

class SomeFinderExtension extends FinderExtension {

 String get finderType => 'SomeFinder';

 SerializableFinder deserialize(Map<String, String> params, DeserializeFinderFactory finderFactory) {
   return SomeFinder(json['title']);
 }

 Finder createFinder(SerializableFinder finder, CreateFinderFactory finderFactory) {
   Some someFinder = finder as SomeFinder;

   return find.byElementPredicate((Element element) {
     final Widget widget = element.widget;
     if (element.widget is SomeWidget) {
       return element.widget.title == someFinder.title;
     }
     return false;
   });
 }
}

Notice find.byElementPredicate which is part of flutter_test CommonFinders and reused for flutter_driver example. I assume it is possible to do that for other ones implemented in flutter_test.

And pass those new finders wrapped into FinderExtension into enableFlutterDriverExtension():

void main() {
  enableFlutterDriverExtension(
    finders: <FinderExtension>[ SomeFinderExtension() ],
    commands: <CommandExtension>[ SomeCommandExtension() ],
  );

  app.main();
}

Then maybe your custom java Finder will work out. But not being flutter/dart dev I can't confirm that case has 100% success rate.

I also face issues with locating elements. I would want to see ChainedFinder for ex. Additionally there is no possibility to get list of elements if search strategy locates >1 elements. It either returns error on FlutterElement interaction, either "returns" only 1st element if firstMatch parameter set to True.

ehabibov avatar Feb 22 '23 16:02 ehabibov