Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver not support custom command of flutter driver #688

Open
DangCao1999 opened this issue May 17, 2024 · 0 comments
Open

Driver not support custom command of flutter driver #688

DangCao1999 opened this issue May 17, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@DangCao1999
Copy link

DangCao1999 commented May 17, 2024

The flutter allows us add new custom command extension CommandExtension
But the appium flutter driver just allows the basic command execute

I tried to use @appium/execute-driver-plugin to reach to driver.executeElementCommand but can not. Could I implement more code for custom commands?

Example for flutter code

import 'package:flutter/material.dart';
import 'package:flutter_driver/src/common/find.dart';
import 'package:flutter_driver/src/common/message.dart';
import 'package:flutter_test/src/controller.dart';
import 'package:flutter_test/src/finders.dart';
import 'package:flutter_driver/driver_extension.dart';

import './main.dart' as app;

/// Custom command
class CustomCommandResult extends Result {
  final Finder finder;
  const CustomCommandResult(this.finder);

  @override
  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      "hasFound": finder.hasFound,
      // "foundMany": finder.found.toList().length,
    };
  }
}

class CustomCommand extends CommandWithTarget {
  CustomCommand(super.finder);

  @override
  String get kind => 'checkVisible';

  CustomCommand.deserialize(super.json, super.finderFactory)
      : super.deserialize();
}

class CustomCommandExtension extends CommandExtension {
  @override
  Future<Result> call(Command command, WidgetController prober,
      CreateFinderFactory finderFactory, CommandHandlerFactory handlerFactory) {
    FlutterDriverExtension flutterDriverExtension =
        handlerFactory as FlutterDriverExtension;

    final CustomCommand customCommand = command as CustomCommand;

    Finder finder = flutterDriverExtension.createFinder(customCommand.finder);

    return Future.value(CustomCommandResult(finder));
  }

  @override
  String get commandKind => "checkVisible";

  @override
  Command deserialize(
      Map<String, String> params,
      DeserializeFinderFactory finderFactory,
      DeserializeCommandFactory commandFactory) {
    return CustomCommand.deserialize(params, finderFactory);
  }
}

void main() {
  enableFlutterDriverExtension(
      commands: [CustomCommandExtension()]);
  app.main();
}

Example for client script

driver.execute("flutter:commandExtension", "checkVisible", finder);
@KazuCocoa KazuCocoa added enhancement New feature or request help wanted Extra attention is needed labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants