How can I use the system back button in an integration test?
So I'm using flutter and am writing integration tests, in most circumstances I can use the AppBar navigation, finding it by tool tip looks like this :
driver.tap(find.byTooltip('Back'));
But one of my tests opens a web page, after this opens I need to carry on with my tests which means I need to press the system back button, is this possible?
many thanks
Do you need to disable or override the back button in your Flutter application? Find out in this tutorial. By default, when the user presses back either using the device's physical or soft key or using the back button on the AppBar, the application will navigate back to the previous screen or quit if it's the last screen in the stack.
You can read more about Flutter Driver here. we’ll use a simple input textfield followed by a button at center of the screen and will validate functioning of these two widgets as a flow using Flutter driver methods. Before we could start using Flutter Driver class, we need to make 2 new test files under a predefined folder named test_driver.
Return to the first route using Navigator.pop () Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .
Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .
If you have adb
installed on your machine, you can run a command to perform the backpress using a keyevent:
import 'dart:io';
await Process.run(
'adb',
<String>['shell', 'input', 'keyevent', 'KEYCODE_BACK'],
runInShell: true,
);
Maybe this can help you
await device.shellExec('input', <String>['keyevent', 'KEYCODE_BACK']);
Found in one of the official flutter driver tests link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With