From 93b0265199a44f2b988a6f8384f8873e3d4bed14 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 9 Aug 2018 16:57:41 -0700 Subject: [PATCH] Fix flutter_gallery_instrumentation_test (#20361) Somehow I forgot to say "super.tap()" when calling "tap()" on the new superclass, so it was just recursing infinitely but ended up actually crashing on the first reuse of the finder. The error was previously swallowed, I made this print it instead. --- .../flutter_gallery_instrumentation_test.dart | 4 +++ .../flutter_gallery/test/live_smoketest.dart | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/dev/devicelab/bin/tasks/flutter_gallery_instrumentation_test.dart b/dev/devicelab/bin/tasks/flutter_gallery_instrumentation_test.dart index 668be9eb22..1434db5a0d 100644 --- a/dev/devicelab/bin/tasks/flutter_gallery_instrumentation_test.dart +++ b/dev/devicelab/bin/tasks/flutter_gallery_instrumentation_test.dart @@ -9,6 +9,10 @@ import 'package:flutter_devicelab/framework/adb.dart'; import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/utils.dart'; +// This test runs "//examples/flutter_gallery/test/live_smoketest.dart", which communicates +// with the Java code to report its status. If this test fails due to a problem on the Dart +// side, you can debug that by just running that file directly using `flutter run`. + Future main() async { deviceOperatingSystem = DeviceOperatingSystem.android; diff --git a/examples/flutter_gallery/test/live_smoketest.dart b/examples/flutter_gallery/test/live_smoketest.dart index 2f080aadd9..36f95c8900 100644 --- a/examples/flutter_gallery/test/live_smoketest.dart +++ b/examples/flutter_gallery/test/live_smoketest.dart @@ -2,6 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ATTENTION! +// +// This file is not named "*_test.dart", and as such will not run when you run +// "flutter test". It is only intended to be run as part of the +// flutter_gallery_instrumentation_test devicelab test. + import 'dart:async'; import 'package:flutter/services.dart'; @@ -43,32 +49,34 @@ Future main() async { if (!new Set.from(allDemoTitles).containsAll(_kSkippedDemoTitles)) fail('Unrecognized demo names in _kSkippedDemoTitles: $_kSkippedDemoTitles'); + print('Starting app...'); runApp(const GalleryApp(testMode: true)); final _LiveWidgetController controller = new _LiveWidgetController(WidgetsBinding.instance); for (GalleryDemoCategory category in kAllGalleryDemoCategories) { + print('Tapping "${category.name}" section...'); await controller.tap(find.text(category.name)); for (GalleryDemo demo in kGalleryCategoryToDemos[category]) { final Finder demoItem = find.text(demo.title); + print('Scrolling to "${demo.title}"...'); await controller.scrollIntoView(demoItem, alignment: 0.5); - - if (_kSkippedDemoTitles.contains(demo.title)) { - print('> skipped $demo'); + if (_kSkippedDemoTitles.contains(demo.title)) continue; - } - for (int i = 0; i < 2; i += 1) { + print('Tapping "${demo.title}"...'); await controller.tap(demoItem); // Launch the demo controller.frameSync = !_kUnsynchronizedDemoTitles.contains(demo.title); + print('Going back to demo list...'); await controller.tap(find.byTooltip('Back')); controller.frameSync = true; } - print('Success'); } + print('Going back to home screen...'); await controller.tap(find.byTooltip('Back')); } - + print('Finished successfully!'); _kTestChannel.invokeMethod('success'); - } catch (error) { + } catch (error, stack) { + print('Caught error: $error\n$stack'); _kTestChannel.invokeMethod('failure'); } } @@ -96,19 +104,16 @@ class _LiveWidgetController extends LiveWidgetController { /// Runs `finder` repeatedly until it finds one or more [Element]s. Future _waitForElement(Finder finder) async { if (frameSync) - await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0); - + await _waitUntilFrame(() => binding.transientCallbackCount == 0); await _waitUntilFrame(() => finder.precache()); - if (frameSync) - await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0); - + await _waitUntilFrame(() => binding.transientCallbackCount == 0); return finder; } @override Future tap(Finder finder, { int pointer }) async { - await tap(await _waitForElement(finder), pointer: pointer); + await super.tap(await _waitForElement(finder), pointer: pointer); } Future scrollIntoView(Finder finder, {double alignment}) async {