我试图设置我的颤音应用程序,以便使用flutter_driver和集成测试实现屏幕截图的自动化,但该应用程序停留在等待*.json文件的未来的时刻。
有人知道怎么解决这个问题吗?
复制步骤
String myJson = await rootBundle.loadString('my_resources/myjson.json');
App.dart:
import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_project/main.dart' as app;
void main() {
// This line enables the extension.
enableFlutterDriverExtension();
// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}App_test.dart:
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() {
group('MyApp', () {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
});
}flutter drive --target=test_driver/app.dart运行
在我的例子中,应用程序被困在等待未来的*.json文件的1.中,使用常规的flutter run命令,一切都如预期的那样工作。
颤振医生-v
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G95, locale de-DE)
• Flutter version 1.9.1+hotfix.2 at /Users/patrick/Development/flutter
• Framework revision 2d2a1ffec9 (2 weeks ago), 2019-09-06 18:39:49 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/patrick/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.38.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.4.1
[✓] Connected device (2 available)
• iPhone 7 • 5E5C912E-EA1D-438B-B5C5-E963D4BF9B33 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
• iPhone Xʀ • EE0825D6-B8B4-4010-B954-CC913953F5D4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
• No issues found!有谁能解决这个问题吗?我想导入的*.json是一个配置文件,因此导入它对于顺利运行是至关重要的。任何解决办法都会很高兴的。
发布于 2019-09-24 16:36:50
在颤振GitHub上有一个突出的问题。它似乎有一个问题的VM和一个隔离颤振驱动器。
请参阅这个注释https://github.com/flutter/flutter/issues/30641#issuecomment-524868136,它有一个指向一个分支的链接,其中有一个测试示例(这里是https://github.com/vishna/flutter/commit/2f858fc334fc2f43b92c318d02bdbf1ad0984033),该测试在传递过程中为我解决了这类问题。
此外,也许值得分享您的源代码,以便人们可以运行/调试等。
发布于 2020-09-15 10:37:28
使用以下代码加载JSON:
static Future<String> getJson(String file) async
{
final ByteData data = await rootBundle.load(file);
if (data == null) return null;
return utf8.decode(data.buffer.asUint8List());
}就像乔治·赫伯特说的--现在有一个悬而未决的问题。所有运行计算的代码都将挂起。
https://stackoverflow.com/questions/58077550
复制相似问题