Проблема FlutterDriver, не удается найти виджет по ключу - PullRequest
2 голосов
/ 07 июня 2019

У меня проблема с поиском виджета по ключу в SerializableFinder, что я могу сделать, чтобы решить эту проблему?

Я попытался создать ключ с константами, и я убедился, чтоключ такой же, как в искателе, предоставляя константы.Кроме того, я имел в виду эту ссылку: Драйвер флаттера: 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: навигация снизуbar

 bottomNavigationBar: BottomNavigationBar(
        key: Key(BOTTOM_NAVIGATION_BAR),
        items: bottomNavigationBarItems,
        currentIndex: currentIndex,
        onTap: (index) {
          changeSelectedBottomNavigationBarItem(index);
        },
        selectedItemColor: appConfig.appColor,
        unselectedItemColor: Colors.grey,
      ),

Если вы хотите предоставить полный код, просто запросите его, я буду очень рад предоставить их.

Ожидаемые результаты: при проведении интеграционного тестирования приложение будет автоматически перемещатьсявыбранный элемент

Фактический результат:

Sneak peek:

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".

Поскольку трассировка стека слишком длинная в ссылке, я предоставлю мой pastebinсюда: https://pastebin.com/p4ktKXLA

1 Ответ

0 голосов
/ 07 июня 2019

Вы использовали findByValueKey, но ваш виджет использует Key вместо ValueKey.

До:

Foo(key: Key(DESSERT))

После:

Foo(key: ValueKey(DESSERT))
...