Unverified Commit ac9dc574 authored by xster's avatar xster Committed by GitHub

Add support for material agnostic driver navigation (#22461)

parent 2a8e35cc
...@@ -13,7 +13,7 @@ class CupertinoProgressIndicatorDemo extends StatelessWidget { ...@@ -13,7 +13,7 @@ class CupertinoProgressIndicatorDemo extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
previousPageTitle: 'Cupertino', previousPageTitle: 'Back',
middle: const Text('Cupertino Activity Indicator'), middle: const Text('Cupertino Activity Indicator'),
trailing: CupertinoDemoDocumentationButton(routeName), trailing: CupertinoDemoDocumentationButton(routeName),
), ),
......
...@@ -45,9 +45,7 @@ const List<String> kUnsynchronizedDemos = <String>[ ...@@ -45,9 +45,7 @@ const List<String> kUnsynchronizedDemos = <String>[
'Video@Media', 'Video@Media',
]; ];
const List<String> kSkippedDemos = <String>[ const List<String> kSkippedDemos = <String>[];
'Pull to refresh@Cupertino', // The back button lacks a tooltip.
];
// All of the gallery demos, identified as "title@category". // All of the gallery demos, identified as "title@category".
// //
...@@ -157,10 +155,10 @@ Future<Null> runDemos(List<String> demos, FlutterDriver driver) async { ...@@ -157,10 +155,10 @@ Future<Null> runDemos(List<String> demos, FlutterDriver driver) async {
if (kUnsynchronizedDemos.contains(demo)) { if (kUnsynchronizedDemos.contains(demo)) {
await driver.runUnsynchronized<void>(() async { await driver.runUnsynchronized<void>(() async {
await driver.tap(find.byTooltip('Back')); await driver.tap(find.pageBack());
}); });
} else { } else {
await driver.tap(find.byTooltip('Back')); await driver.tap(find.pageBack());
} }
} }
......
...@@ -136,6 +136,7 @@ abstract class SerializableFinder { ...@@ -136,6 +136,7 @@ abstract class SerializableFinder {
case 'ByValueKey': return ByValueKey.deserialize(json); case 'ByValueKey': return ByValueKey.deserialize(json);
case 'ByTooltipMessage': return ByTooltipMessage.deserialize(json); case 'ByTooltipMessage': return ByTooltipMessage.deserialize(json);
case 'ByText': return ByText.deserialize(json); case 'ByText': return ByText.deserialize(json);
case 'PageBack': return PageBack();
} }
throw DriverError('Unsupported search specification type $finderType'); throw DriverError('Unsupported search specification type $finderType');
} }
...@@ -253,6 +254,17 @@ class ByType extends SerializableFinder { ...@@ -253,6 +254,17 @@ class ByType extends SerializableFinder {
} }
} }
/// A Flutter Driver finder that finds the back button on the page's Material
/// or Cupertino scaffold.
///
/// See also:
///
/// * [WidgetTester.pageBack], for a similar functionality in widget tests.
class PageBack extends SerializableFinder {
@override
String get finderType => 'PageBack';
}
/// A Flutter driver command that retrieves a semantics id using a specified finder. /// A Flutter driver command that retrieves a semantics id using a specified finder.
/// ///
/// This command requires assertions to be enabled on the device. /// This command requires assertions to be enabled on the device.
......
...@@ -854,4 +854,7 @@ class CommonFinders { ...@@ -854,4 +854,7 @@ class CommonFinders {
/// Finds widgets whose class name matches the given string. /// Finds widgets whose class name matches the given string.
SerializableFinder byType(String type) => ByType(type); SerializableFinder byType(String type) => ByType(type);
/// Finds the back button on a Material or Cupertino page's scaffold.
SerializableFinder pageBack() => PageBack();
} }
...@@ -7,6 +7,7 @@ import 'dart:async'; ...@@ -7,6 +7,7 @@ import 'dart:async';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -138,6 +139,7 @@ class FlutterDriverExtension { ...@@ -138,6 +139,7 @@ class FlutterDriverExtension {
'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder), 'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder),
'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder), 'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder),
'ByType': (SerializableFinder finder) => _createByTypeFinder(finder), 'ByType': (SerializableFinder finder) => _createByTypeFinder(finder),
'PageBack': (SerializableFinder finder) => _createPageBackFinder(),
}); });
} }
...@@ -274,6 +276,17 @@ class FlutterDriverExtension { ...@@ -274,6 +276,17 @@ class FlutterDriverExtension {
}, description: 'widget with runtimeType "${arguments.type}"'); }, description: 'widget with runtimeType "${arguments.type}"');
} }
Finder _createPageBackFinder() {
return find.byElementPredicate((Element element) {
final Widget widget = element.widget;
if (widget is Tooltip)
return widget.message == 'Back';
if (widget is CupertinoNavigationBarBackButton)
return true;
return false;
}, description: 'Material or Cupertino back button');
}
Finder _createFinder(SerializableFinder finder) { Finder _createFinder(SerializableFinder finder) {
final FinderConstructor constructor = _finders[finder.finderType]; final FinderConstructor constructor = _finders[finder.finderType];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment