mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Add getRenderTree() to Flutter Driver (#7007)
Returns a dump of the application's render tree.
This commit is contained in:
parent
dba0e3f6ae
commit
c4afe9589b
|
@ -16,6 +16,7 @@ import 'gesture.dart';
|
|||
import 'health.dart';
|
||||
import 'input.dart';
|
||||
import 'message.dart';
|
||||
import 'render_tree.dart';
|
||||
import 'timeline.dart';
|
||||
|
||||
/// Timeline stream identifier.
|
||||
|
@ -244,6 +245,11 @@ class FlutterDriver {
|
|||
return Health.fromJson(await _sendCommand(new GetHealth()));
|
||||
}
|
||||
|
||||
/// Returns a dump of the render tree.
|
||||
Future<RenderTree> getRenderTree() async {
|
||||
return RenderTree.fromJson(await _sendCommand(new GetRenderTree()));
|
||||
}
|
||||
|
||||
/// Taps at the center of the widget located by [finder].
|
||||
Future<Null> tap(SerializableFinder finder) async {
|
||||
await _sendCommand(new Tap(finder));
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart' show RendererBinding;
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -16,6 +17,7 @@ import 'gesture.dart';
|
|||
import 'health.dart';
|
||||
import 'input.dart';
|
||||
import 'message.dart';
|
||||
import 'render_tree.dart';
|
||||
|
||||
const String _extensionMethodName = 'driver';
|
||||
const String _extensionMethod = 'ext.flutter.$_extensionMethodName';
|
||||
|
@ -61,6 +63,7 @@ class _FlutterDriverExtension {
|
|||
_FlutterDriverExtension._() {
|
||||
_commandHandlers.addAll(<String, CommandHandlerCallback>{
|
||||
'get_health': _getHealth,
|
||||
'get_render_tree': _getRenderTree,
|
||||
'tap': _tap,
|
||||
'get_text': _getText,
|
||||
'scroll': _scroll,
|
||||
|
@ -72,6 +75,7 @@ class _FlutterDriverExtension {
|
|||
|
||||
_commandDeserializers.addAll(<String, CommandDeserializerCallback>{
|
||||
'get_health': GetHealth.deserialize,
|
||||
'get_render_tree': GetRenderTree.deserialize,
|
||||
'tap': Tap.deserialize,
|
||||
'get_text': GetText.deserialize,
|
||||
'scroll': Scroll.deserialize,
|
||||
|
@ -135,6 +139,10 @@ class _FlutterDriverExtension {
|
|||
|
||||
Future<Health> _getHealth(Command command) async => new Health(HealthStatus.ok);
|
||||
|
||||
Future<RenderTree> _getRenderTree(Command command) async {
|
||||
return new RenderTree(RendererBinding.instance?.renderView?.toStringDeep());
|
||||
}
|
||||
|
||||
/// Runs `finder` repeatedly until it finds one or more [Element]s, or times out.
|
||||
///
|
||||
/// The timeout is five seconds.
|
||||
|
|
37
packages/flutter_driver/lib/src/render_tree.dart
Normal file
37
packages/flutter_driver/lib/src/render_tree.dart
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'message.dart';
|
||||
|
||||
/// A request for a string representation of the render tree.
|
||||
class GetRenderTree implements Command {
|
||||
@override
|
||||
final String kind = 'get_render_tree';
|
||||
|
||||
/// Deserializes the command from JSON generated by [serialize].
|
||||
static GetRenderTree deserialize(Map<String, String> json) => new GetRenderTree();
|
||||
|
||||
@override
|
||||
Map<String, String> serialize() => const <String, String>{};
|
||||
}
|
||||
|
||||
/// A string representation of the render tree.
|
||||
class RenderTree extends Result {
|
||||
/// Creates a [RenderTree] object with the given string representation.
|
||||
RenderTree(this.tree);
|
||||
|
||||
/// Deserializes the result from JSON.
|
||||
static RenderTree fromJson(Map<String, dynamic> json) {
|
||||
return new RenderTree(json['tree']);
|
||||
}
|
||||
|
||||
/// String representation of the render tree.
|
||||
final String tree;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'tree': tree
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in a new issue