Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using the system back button from flutter driver

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

like image 206
martinseal1987 Avatar asked Mar 01 '19 15:03

martinseal1987


People also ask

Do you need to disable or override the back button in flutter?

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.

How to validate function of two widgets using flutter driver?

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.

How to return to the first route in flutter?

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 .

What are screens and pages in flutter?

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 .


2 Answers

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,
);
like image 137
Miguel Beltran Avatar answered Sep 28 '22 10:09

Miguel Beltran


Maybe this can help you

 await device.shellExec('input', <String>['keyevent', 'KEYCODE_BACK']);

Found in one of the official flutter driver tests link

like image 38
David Beljan Avatar answered Sep 28 '22 09:09

David Beljan