Flutter驱动程序:测试BottomNavigationBarItem [英] Flutter Driver: Test BottomNavigationBarItem

查看:130
本文介绍了Flutter驱动程序:测试BottomNavigationBarItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过 FlutterDriver 测试BottomNavigationBarItem?

how do I test BottomNavigationBarItems via FlutterDriver?

FlutterDriver 允许通过 text byValueKey byTooltip byType

但这些都不是方法对我的应用程序有效,原因如下:

But none of these methods work out for my App because of following reasons:


  • 文本:该应用程序已本地化并我需要以多种语言测试该应用程序。

  • text: The App is localized and I need to test the App in multiple languages.

byValueKey :BottomNavigationBarItems没有 key 属性。

byValueKey: BottomNavigationBarItems do not have key properties.

byTooltip :BottomNavigationBarItem不具有 toolTip 属性。

byTooltip: BottomNavigationBarItems do not have toolTip properties.

byType :byType仅返回该类型的第一个匹配项,并且不列出任何列表(因为我有多个标签,因此是必需的)。

byType: byType only returns the first match of the type and no list (needed because I have multiple tabs).

非常感谢!

干杯。

推荐答案

不是确定您是否找到了此问题的答案,但是我将在此处发布对我有用的解决方案。基本上, BottomNavigationBar 有一个 key 属性需要使用。一旦Flutter Driver识别了此键,您就可以告诉驱动程序点击其任何子项,即 BottomNavigationBarItem

Not sure if you have found answer for this question, but I am going to post a solution here which works for me. Basically, BottomNavigationBar has a key property which you need to use. Once Flutter Driver identifies this key, then you can tell driver to tap on any of its child items ie BottomNavigationBarItem.

我的屏幕上有2个 bottomNavigationBarItems ,如下所示,我为其父窗口小部件定义了键,即 BottomNavigationBar 如下:

My screen has 2 bottomNavigationBarItems as shown below and I defined key for their parent widget ie BottomNavigationBar as:

bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.shifting,
        key: Key('bottom'),
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.ac_unit, color: Colors.green,),
            title: Text('First', style: TextStyle(color: Colors.black),)
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.cast, color: Colors.yellow,),
            title: Text('Second', style: TextStyle(color: Colors.black),)
          )
        ],
      ),

然后我写了一个flutter驱动程序测试,以同时使用两个都可以正常工作的项目。

And I wrote a flutter driver test to tap on both items which worked perfectly.

test('bottomnavigationbar test', () async {
      await driver.waitFor(find.byValueKey('bottom'));
      await driver.tap(find.text('First'));
      print('clicked on first');
      await driver.tap(find.text('Second'));
      print('clicked on second too');
    });

结果:

这篇关于Flutter驱动程序:测试BottomNavigationBarItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆