Quickly press keys
With a Flutter WidgetTester
, common shortcut key presses require 3-5 method calls. With flutter_test_robots
, you only need to make a single method call.
With Flutter Test Robots
testWidgets((tester) async {
// Setup the test.
// Press CMD+V (like for a paste).
await tester.pressCmdV();
// Press CMD+ALT+LEFT (jump to start).
await tester.pressCmdAltLeftArrow();
// Verify expectations.
});
With Flutter
testWidgets((tester) async {
// Setup the test.
// Press CMD+V (like for a paste).
await tester.sendKeyDownEvent(
LogicalKeyboardKey.meta,
);
await tester.sendKeyEvent(
LogicalKeyboardKey.keyV,
);
await tester.sendKeyUpEvent(
LogicalKeyboardKey.meta,
);
// Press CMD+ALT+LEFT (jump to start).
await tester.sendKeyDownEvent(
LogicalKeyboardKey.meta,
);
await tester.sendKeyDownEvent(
LogicalKeyboardKey.alt,
);
await tester.sendKeyEvent(
LogicalKeyboardKey.left,
);
await tester.sendKeyUpEvent(
LogicalKeyboardKey.alt,
);
await tester.sendKeyUpEvent(
LogicalKeyboardKey.meta,
);
// Verify expectations.
});
Simulate a user typing
The flutter_test_robots
package offers unique tools for simulating user typing input. You can either simulate input through the OS Input Method Editor (IME), or through direct physical keyboard key pressed.
Simulate IME input
When you want to simulate IME text input, flutter_test_robots
generates IME insertion deltas for every character in your text and then sends them through Flutter’s IME communication channel.
testWidgets((tester) async {
// Setup the test.
// Type “Hello, World!” via IME.
await tester.ime.typeText("Hello, World!");
// Verify expectations.
});
Simulate Keyboard Input
When you want to simulate hardware keyboard text input, flutter_test_robots
maps every character of your text to a physical key press and then simulates that press.
testWidgets((tester) async {
// Setup the test.
// Type “Hello, World!” via physical keyboard.
await tester.typeKeyboardText(
"Hello, World!"
);
// Verify expectations.
});
Built by the
Flutter Bounty Hunters
This package was built by the Flutter Bounty Hunters (FBH). The Flutter Bounty Hunters is a development agency that works exclusively on open source Flutter and Dark packages.
With funding from corporate clients, the goal of the Flutter Bounty Hunters is to solve common problems for The Last Time™. If your team gets value from Flutter Bounty Hunter packages, please consider funding further development.
Other FBH packages
Other packages that the Flutter Bounty Hunters brought to the community...
Super Editor, Super Text, Attributed Text, Static Shock, Follow the Leader, Overlord, Flutter Test Robots, and more.
Contributors
The flutter_test_robots
package was built by...