【问题标题】:how should i find a global key in flutter driver test?我应该如何在颤振驱动程序测试中找到全局密钥?
【发布时间】:2021-06-10 08:28:19
【问题描述】:

通常我将 Key: ValueKey 放在我想在我的测试用例中找到用于测试的颤振元素中,但是这个特定元素已经有一个 globalKey。那么,我应该使用什么来查找元素中使用的 globalkey 呢?

值键

key: ValueKey('nameField')

在测试用例中 => final nameField = find.byValueKey('nameField')

全局键

final LabeledGlobalKey<FormFieldState<String>> _passwordField = LabeledGlobalKey<FormFieldState<String>>("passwordFieldKey")

key: _passwordField

在测试用例中 => final passwordField = find.???('???')

【问题讨论】:

    标签: flutter-test flutterdriver


    【解决方案1】:

    我认为不可能找到GlobalKeys(我曾经用来查找某些小部件的位置),但您可以找到Keys。所以我所做的是:将我在测试中必须找到的小部件包装成一个具有 GlobalKey 的容器小部件。

    GlobalKey someKeyName = GlobalKey();
    
    Container(
        key: someKeyName,
        child: CustomButton(
          key: Key('Key that I would look for in my Integration Test'),
          child: Text('Press Me'),
        ),
    );
    

    我不确定 LabeledGlobalKey<FormFieldState<String>> 做了什么,但希望这个解决方法可以帮助您解决问题。

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 2018-03-10
      • 2020-06-20
      • 2021-10-23
      • 2021-10-30
      • 2019-11-11
      • 2020-04-23
      • 2021-08-17
      • 2021-03-09
      相关资源
      最近更新 更多