Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter driver fails on dart:ui (even if no ui components are imported) #27826

Closed
Sadoge opened this issue Feb 12, 2019 · 14 comments

Comments

Projects
None yet
5 participants
@Sadoge
Copy link

commented Feb 12, 2019

When trying to run the flutter driver, it fails because of dart:ui, but in none of my tests I am importing any widgets. As you can see it is failing on the material package, which is used to run the app in the first place (or run flutter driver)

Logs

file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/colors.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show Color;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/dialog_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/input_border.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/input_decorator.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///Users/sam/Library/Developer/Flutter/flutter/packages/flutter/lib/src/material/mergeable_material.dart:5:8: Error: Not found: 'dart:ui'

Flutter doctor

[✓] Flutter (Channel beta, v1.1.8, on Mac OS X 10.14 18A391, locale en-PH)
    • Flutter version 1.1.8 at /Users/sam/Library/Developer/Flutter/flutter
    • Framework revision 985ccb6d14 (5 weeks ago), 2019-01-08 13:45:55 -0800
    • Engine revision 7112b72cc2
    • Dart version 2.1.1 (build 2.1.1-dev.0.1 ec86471ccc)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/sam/Library/Developer/Xamarin/android-sdk-macosx
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/sam/Library/Developer/Xamarin/android-sdk-macosx
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[!] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Community Edition (version 2018.1.6)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 26.0.2
    • Dart plugin version 181.4892.1

[✓] VS Code (version 1.30.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.22.3

[✓] Connected device (1 available)
    • iPhone XR • 7E54F1F3-2AA7-4C64-9B37-19051D3924B4 • ios • iOS 12.1 (simulator)
@zoechi

This comment has been minimized.

Copy link
Contributor

commented Feb 12, 2019

Seems you are indirectly importing it by importing animated_icons.dart directly or indirectly.
The test file can not contain anything Flutter specific because it is not run on a device/emulator, only the driven app can import such libraries.

@Sadoge

This comment has been minimized.

Copy link
Author

commented Feb 13, 2019

So then I am not able to import the material library (since this one includes the animated_icons.dart)? Since that one is used for the runApp function in the integration tests. By the way, this worked perfectly fine up to recently where it suddenly started failing and we did not change anything to our test files, and do not import any new things.

Edit:
Just tested it by removing 'animated_icons.dart' import from material.dart and then it does not fail on that line anymore. What is the alternative for material when testing?

@zoechi

This comment has been minimized.

Copy link
Contributor

commented Feb 13, 2019

It's not clear to me what you try to accomplish. There is no point in importing any such stuff in the driver code, only in the app code.

@Sadoge

This comment has been minimized.

Copy link
Author

commented Feb 13, 2019

I am trying to test the app screen by screen, by running it on an emulator with flutter driver and with flutter driver I can test the app itself right? I need to run the app to be able to test it like shown in the documentation here -> https://flutter.io/docs/cookbook/testing/integration/introduction. It still imports the main.dart file (which has the material.dart). So that is the exact thing that I am doing but still it fails with the same error

@zoechi

This comment has been minimized.

Copy link
Contributor

commented Feb 13, 2019

You can't import the main.dart file in the test file if it imports dart:ui directly or indirectly.
Why do you want to do that?

@Sadoge

This comment has been minimized.

Copy link
Author

commented Feb 13, 2019

How will I test the app with integration tests then? Even in the documentation of Flutter it gives me an example that this is possible and how it is done? See link in my comment above

screen shot 2019-02-13 at 15 18 58

@zoechi

This comment has been minimized.

Copy link
Contributor

commented Feb 13, 2019

Somehow you seem to mix up driver test and app. This is only an alternative main.dart file for the app to have flutterDriverExtension enabled. This is not the driver test file.

To investigate we would need a minimal reproduction project and the exact command you use to run,

but actually I think this is a support case that should be asked
in one of the other channels listed at http://flutter.io/support .

@ZeekHuge

This comment has been minimized.

Copy link

commented Apr 4, 2019

Hi !
(Please let me know If I should open a new issue for this, as this has been closed [without any solution ?])
I am facing the same issue when trying to do integration-testing, that is, the error is :


> flutter driver --target=test_driver/app.dart
Using device Android SDK built for x86.
Starting application: test_driver/app.dart
Initializing gradle...                                                  9.9s
Resolving dependencies...                                               7.0s
Installing build/app/outputs/apk/app.apk...                            19.6s
Running Gradle task 'assembleDebug'...                                      
Running Gradle task 'assembleDebug'... Done                        18.1s
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...                             8.0s
I/flutter ( 9738): Observatory listening on http://127.0.0.1:54422/
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/card_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/chip_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/colors.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show Color;
       ^
file:///home/zeekhuge/flutter-installed/flutter/packages/flutter/lib/src/material/dialog_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
Stopping application instance.
Driver tests failed: 254

Note the command I am using to run the tests is : flutter driver --target=test_driver/app.dart

The source code is here, the actual test file being test_driver/home_page.dart
Now, By little playing-around, it can be found that this exception is being caused due to the flutter/material.dart import, but for my use-case that will be required, to be able to use methods like find.byIcon() etc. Also, since these tests should be running on the actual device, and are Integration tests, I believe "everything" should be available to the test runtime and that "everything" should get tested like a real device.

So, how should I go about solving this exception ? Would also be happy to submit a PR with some guidance from you guys.

@Sadoge

This comment has been minimized.

Copy link
Author

commented Apr 4, 2019

The solution was indeed that there is no dart:ui imports allowed. I was in some file still referencing the material library after a long search through my files and after removing it, it worked perfectly fine again. So if you want to use the find.ByIcon , that will not work in integration tests, what will work tho is byType or byKey and giving a specific key to that icon that you want to use in the test and works fine as well

@ZeekHuge

This comment has been minimized.

Copy link

commented Apr 4, 2019

@Sadoge : Okay. So that will add an overhead of using indirect methods (keys etc), over more direct methods (Icons etc). And I think I can live with that, but conceptually this does not sound right. These integration tests are meant to be tests on a full-fledged application. And, the application does use the material library, so, I would expect the integration tests to work fine with the library.

@Sadoge

This comment has been minimized.

Copy link
Author

commented Apr 4, 2019

I fully agree on that, since these testing methods are available on the widget tests, only thing is that I do not know if this is possible, since I do not know the ins and outs of the code.

@ZeekHuge

This comment has been minimized.

Copy link

commented Apr 4, 2019

Okay, I think I get it now. When doing the integration tests, Flutter does not really start the actual app, but the --target app, which in turn starts the actual "app" from inside it. This target app then executes commands and actions over the actual app's UI. So the actual run-time is not the app, but the target app, which is termed as "Driver" app. And it's this driver run-time, which lacks all these flutter libraries.

Its unlike espresso, because (not sure if this is correct) espresso had access to the core system APIs since they were present on the Android OS itself, which, in case of flutter, the Android system does not have.

So, I would think that there should probably be more FlutterDriver#*() APIs to make testing a little more smooth. For example, I cannot use expect(someSerializableFinder, findsOneWidget);, because it will require me to import flutter_test.dart which will again produce the same exception. I will instead have to use driver.waitFor(someSerializableFinder, timeout: Duration(microseconds:<some duration>), which, to be honest, I am not sure if is the correct way to assert existence of a widget.

Moreover, I think there should be something in the documentation to make a clear distinction between the "Driver" app and the "Actual" app. Would be happy to add something in the docs regarding this, if possible.

@MDuRieu

This comment has been minimized.

Copy link

commented Apr 8, 2019

@ZeekHuge your repo saved me from pulling my hair out!!
I've been going through the integration test tutorials on the flutter site and was hitting this dart.ui problem on them, as well. For anyone else still having trouble, this is what sent me off the path:
At some point, it appears flutter went from using
import 'package:test/test.dart';
to using
import 'package:flutter_test/flutter_test.dart';
for doing non-integration unit tests etc. It appeared to me that test/test.dart had just been renamed and the convention changed to use the name flutter_test. As most of the tutorials don't show all the pubspec info, it was difficult to tell (being new to the platform) what was going on.

This led me to believe that test/test.dart was deprecated and some tutorials were just out of date.

So, for doing unit tests/widget tests etc you can put in your pubspec
dev_dependencies:
flutter_test:
sdk: flutter

and use
import 'package:flutter_test/flutter_test.dart';
in your regular testing directory

If you are doing integration tests and using Flutter Driver (and are creating the test_driver directory) to test app elements while running it on a real device or emulator, then in your pubspec put
dev_dependencies:
flutter_driver:
sdk: flutter
test: any

and in your app_test.dart, import
import 'package:flutter_driver/flutter_driver.dart' ; import 'package:test/test.dart';

I saw so many posts saying that the Driver test file can't use flutter elements but wasn't quite sure what that meant in this case. Evidently, the flutter_test.dart import being used in the app_test.dart file is what's trying to find some UI dependencies and using test/test.dart instead overcomes that.

You will also find that if you try to use flutter_driver and flutter_test in the same test file, you will get conflicts trying to use the find function.

@rogerfsgDC

This comment has been minimized.

Copy link

commented Jul 16, 2019

Same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.