Add support for material agnostic driver navigation (#22461)
This commit is contained in:
@@ -13,7 +13,7 @@ class CupertinoProgressIndicatorDemo extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
previousPageTitle: 'Cupertino',
|
||||
previousPageTitle: 'Back',
|
||||
middle: const Text('Cupertino Activity Indicator'),
|
||||
trailing: CupertinoDemoDocumentationButton(routeName),
|
||||
),
|
||||
|
||||
@@ -45,9 +45,7 @@ const List<String> kUnsynchronizedDemos = <String>[
|
||||
'Video@Media',
|
||||
];
|
||||
|
||||
const List<String> kSkippedDemos = <String>[
|
||||
'Pull to refresh@Cupertino', // The back button lacks a tooltip.
|
||||
];
|
||||
const List<String> kSkippedDemos = <String>[];
|
||||
|
||||
// All of the gallery demos, identified as "title@category".
|
||||
//
|
||||
@@ -157,10 +155,10 @@ Future<Null> runDemos(List<String> demos, FlutterDriver driver) async {
|
||||
|
||||
if (kUnsynchronizedDemos.contains(demo)) {
|
||||
await driver.runUnsynchronized<void>(() async {
|
||||
await driver.tap(find.byTooltip('Back'));
|
||||
await driver.tap(find.pageBack());
|
||||
});
|
||||
} else {
|
||||
await driver.tap(find.byTooltip('Back'));
|
||||
await driver.tap(find.pageBack());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ abstract class SerializableFinder {
|
||||
case 'ByValueKey': return ByValueKey.deserialize(json);
|
||||
case 'ByTooltipMessage': return ByTooltipMessage.deserialize(json);
|
||||
case 'ByText': return ByText.deserialize(json);
|
||||
case 'PageBack': return PageBack();
|
||||
}
|
||||
throw DriverError('Unsupported search specification type $finderType');
|
||||
}
|
||||
@@ -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.
|
||||
///
|
||||
/// This command requires assertions to be enabled on the device.
|
||||
|
||||
@@ -854,4 +854,7 @@ class CommonFinders {
|
||||
|
||||
/// Finds widgets whose class name matches the given string.
|
||||
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';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -138,6 +139,7 @@ class FlutterDriverExtension {
|
||||
'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder),
|
||||
'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder),
|
||||
'ByType': (SerializableFinder finder) => _createByTypeFinder(finder),
|
||||
'PageBack': (SerializableFinder finder) => _createPageBackFinder(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,6 +276,17 @@ class FlutterDriverExtension {
|
||||
}, 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) {
|
||||
final FinderConstructor constructor = _finders[finder.finderType];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user