我在SerializableFinder中通过键找到小工具时遇到了问题,我能做些什么来解决这个问题呢?
我已经尝试使用常量来创建键,并且我确保通过提供常量来检查键是否与finder中的键相同。此外,我指的是这个链接:Flutter Driver: Test BottomNavigationBarItem
以下是代码:集成测试文件(示例部分,不是完整代码):
// todo: bottom navigation pressed
test('bottom navigation bar test item', () async{
// todo: intended = pressed favorite dessert, but we want to test
await flutterDriver.waitFor(bottomNavigationBar);
// todo: bottom navigation bar item text research
await flutterDriver.tap(dessert); // intended : tap at bottom navigation view item
print('This is Dessert section');
// todo: expect title is keyword
await flutterDriver.tap(seafood);
print('This is Seafood section');
await flutterDriver.tap(favoriteDessert);
print('This is Favorite Dessert section');
await flutterDriver.tap(favoriteSeafood);
print('This is Favorite Seafood section');
});Finder文件(用于底部导航栏):
SerializableFinder bottomNavigationBar = find.byValueKey(BOTTOM_NAVIGATION_BAR);
SerializableFinder dessert = find.byValueKey(DESSERT);
SerializableFinder seafood = find.byValueKey(SEAFOOD);
SerializableFinder favoriteDessert = find.byValueKey(FAVORITE_DESSERT);
SerializableFinder favoriteSeafood = find.byValueKey(FAVORITE_SEAFOOD);小部件文件(2部分):第1部分:底部导航栏项目
List<BottomNavigationBarItem> bottomNavigationBarItems = [
BottomNavigationBarItem(
icon: Icon(Icons.cake, key: Key(DESSERT)), title: Text("Dessert")),
BottomNavigationBarItem(
icon: Icon(Icons.restaurant, key : Key(SEAFOOD)), title: Text("Seafood")),
BottomNavigationBarItem(
icon: Icon(Icons.cake, key: Key(FAVORITE_DESSERT)), title: Text("Favorite Dessert")),
BottomNavigationBarItem(
icon: Icon(Icons.restaurant, key: Key(FAVORITE_SEAFOOD)), title: Text("Favorite Seafood"))
];第2部分:底部导航栏
bottomNavigationBar: BottomNavigationBar(
key: Key(BOTTOM_NAVIGATION_BAR),
items: bottomNavigationBarItems,
currentIndex: currentIndex,
onTap: (index) {
changeSelectedBottomNavigationBarItem(index);
},
selectedItemColor: appConfig.appColor,
unselectedItemColor: Colors.grey,
),如果你想提供完整的代码只是要求它,我将非常乐意提供他们。
预期结果:在进行集成测试时,应用程序将自动导航所选项目
实际结果:
偷看:
00:02 +0: Meals Catalogue App bottom navigation bar test item
[warning] FlutterDriver: waitFor message is taking a long time to complete...
00:32 +0 -1: Meals Catalogue App bottom navigation bar test item [E]
TimeoutException after 0:00:30.000000: Test timed out after 30 seconds.00:32 +0 -1: Meals Catalogue App (tearDownAll)
00:32 +0 -1: Meals Catalogue App bottom navigation bar test item [E]
DriverError: Failed to fulfill WaitFor due to remote error
Original error: Bad state: The client closed with pending request "ext.flutter.driver".由于堆栈跟踪在链接中有点太长,我将在这里提供我的粘贴库:https://pastebin.com/p4ktKXLA
发布于 2019-11-07 23:26:00
我也遇到了同样的问题,最终帮助我的解决方案来自Pyozer
默认情况下,颤动驱动程序是帧同步的,它将一直等到没有挂起的帧,但如果有无限的动画,测试将进入超时并失败。
要解决这个问题,您需要用driver.runUnsynchronized()方法包装测试。如下所示:
test('Test SplashScreen', () async {
await driver.runUnsynchronized(() async {
await driver.waitFor(find.text("DESSERT"));
});
});(仅当您有无限动画或想要在动画结束前继续时)
https://stackoverflow.com/questions/56492561
复制相似问题