gpt4 book ai didi

android - Flutter Driver 测试超时

转载 作者:行者123 更新时间:2023-12-03 02:42:05 25 4
gpt4 key购买 nike

我是 Flutter Driver 测试的新手,我遇到一个问题,即在等待小部件出现时测试总是超时(30 秒内)。我的主要类(class)只是检查 Firebase 用户是否不为空。如果用户已登录,则显示仪表板,否则显示登录屏幕。运行检查时,它显示一个 SplashScreen。测试“检查 flutter 驱动程序健康”正常完成。

我试过find.byValueKey("auth_screen")而不是 find.byType("AuthScreen") ,它给出了同样的问题。

错误日志:

VMServiceFlutterDriver: Connected to Flutter application.
00:01 +0: rendin app check flutter driver health

HealthStatus.ok

00:01 +1: rendin app Check login screen widgets

Splash screen

VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
00:31 +1 -1: rendin app Check login screen widgets [E]

TimeoutException after 0:00:30.000000: Test timed out after 30 seconds.

Bad state: The client closed with pending request "ext.flutter.driver".

这是我的测试代码:
import 'package:test/test.dart';
import 'package:flutter_driver/flutter_driver.dart';

import 'package:test/test.dart';

void main() {
group('app', () {
FlutterDriver driver;

// Connect to the Flutter driver before running any tests.
setUpAll(() async {
driver = await FlutterDriver.connect();
});

test('check flutter driver health', () async {
Health health = await driver.checkHealth();
print(health.status);
});

test("Check login screen", () async {

await driver.waitFor(find.byType("AuthScreen")).then((value) async {
print("Auth screen");
});
});

// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
});
}

主类中的一段 futureBuilder 代码:
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return SplashScreen(key: Key("splashScreen2"));
} else if (snapshot.hasData) {
return DashboardScreen();
} else {
return AuthScreen();
}
},

和 AuthScreen() 一段代码:
class AuthScreen extends StatelessWidget {
static const routeName = '/auth';

@override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;
return Scaffold(
key: Key("auth_screen"),
backgroundColor: Colors.white,

最佳答案

test()有一个名为 timeout 的参数

这是演示:

test("Check login screen", () async {

await driver.waitFor(find.byType("AuthScreen")).then((value) async {
print("Auth screen");
});
}, timeout:Timeout.none);

哪个超时默认值 = 30 秒;

关于android - Flutter Driver 测试超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60726510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com