首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FlutterDriver问题,无法通过密钥找到小部件

FlutterDriver问题,无法通过密钥找到小部件
EN

Stack Overflow用户
提问于 2019-06-07 18:26:10
回答 1查看 3.5K关注 0票数 12

我在SerializableFinder中通过键找到小工具时遇到了问题,我能做些什么来解决这个问题呢?

我已经尝试使用常量来创建键,并且我确保通过提供常量来检查键是否与finder中的键相同。此外,我指的是这个链接:Flutter Driver: Test BottomNavigationBarItem

以下是代码:集成测试文件(示例部分,不是完整代码):

代码语言:javascript
复制
// 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文件(用于底部导航栏):

代码语言:javascript
复制
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部分:底部导航栏项目

代码语言:javascript
复制
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部分:底部导航栏

代码语言:javascript
复制
 bottomNavigationBar: BottomNavigationBar(
        key: Key(BOTTOM_NAVIGATION_BAR),
        items: bottomNavigationBarItems,
        currentIndex: currentIndex,
        onTap: (index) {
          changeSelectedBottomNavigationBarItem(index);
        },
        selectedItemColor: appConfig.appColor,
        unselectedItemColor: Colors.grey,
      ),

如果你想提供完整的代码只是要求它,我将非常乐意提供他们。

预期结果:在进行集成测试时,应用程序将自动导航所选项目

实际结果:

偷看:

代码语言:javascript
复制
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.
代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2019-11-07 23:26:00

我也遇到了同样的问题,最终帮助我的解决方案来自Pyozer

默认情况下,颤动驱动程序是帧同步的,它将一直等到没有挂起的帧,但如果有无限的动画,测试将进入超时并失败。

要解决这个问题,您需要用driver.runUnsynchronized()方法包装测试。如下所示:

代码语言:javascript
复制
test('Test SplashScreen', () async {
  await driver.runUnsynchronized(() async {
    await driver.waitFor(find.text("DESSERT"));
  });
});

(仅当您有无限动画或想要在动画结束前继续时)

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56492561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档