leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
874 stars 131 forks source link

Close keyboard if opened #66

Open bartekpacia opened 2 years ago

bartekpacia commented 2 years ago

There's no easy way to do this using UiAutomator.

There's a hack though. An ugly one, but ~it works~ it works only through ADB.

Here's the link

bartekpacia commented 2 years ago

We cannot call adb shell dumpsys from the app (this also applies to test instrumentation), see this.

An (overengineered?) workaround could be running some second simple "maestro daemon" process on the host machine.

Edit: After giving it some thought, I think that maestro_cli could have a simple HTTP (or gRPC, now that we've migrated to gRPC) server in itself. Then we could make requests from the integration test to the CLI, which runs on the host machine and has full access to powerful debugging tools like adb and idb.

Example

Take this code snippet:

import 'package:maestro_test/maestro_test.dart';

Automator.init(verbose: true);
final automator = Automator.instance;

// ...

Automator.isKeyboardOpened()

would make a HTTP request not to the connected Android device, but to the maestro daemon instead. Then the maestro deamon would be able to adb shell dumpsys.

Pros:

Cons:

bartekpacia commented 2 years ago

Another idea worth trying out: use UiAutomation.executeShellCommand instead of UiDevice.executeShellCommand

bartekpacia commented 2 years ago

We could see how Maestro by mobile.dev does this.

See:

bartekpacia commented 1 year ago

We could differentiate between host services and local services (ADB does it).

bartekpacia commented 1 year ago

Important update

In #593 we've got a powerful new capability of acting as a host. This means we're able to use adb and programmatically hide keyboard.

Here's how Maestro does this – the hideKeyboard() method.

bartekpacia commented 1 year ago

We lost this feature in 1.0 :)

yacineblr commented 6 months ago

Do you have any news about this please ?