如何 select 集成测试中的 flutters 时间选择器

How to select a time in flutters time picker from integration test

我正在为 flutter 应用程序编写集成测试,我需要打开时间选择器和 select 时间,它是 android 中的时间选择器对话框,我可以点击时间在选择器上方并点击确定和取消按钮,但我无法更改拨号的 selected 时间。查看他们的小部件测试,他们正在使用偏移量对其进行测试,我不确定如何从集成测试中执行此操作。我已经创建了一个演示并截取了 flutter 小部件树的屏幕截图,您可以在其中看到拨号和手势检测器等,但是没有任何键可以找到并且尝试通过文本查找也不可能,深入研究源代码代码他们创建了一个 _TappableLabel 列表,它从画家那里获取文本,有人有办法做到这一点吗?

受 timepicker 单元测试的启发,这样做是可行的:

    var center = tester
        .getCenter(find.byKey(const ValueKey<String>('time-picker-dial')));

    await tester.tapAt(Offset(center.dx - 10, center.dy));

由于表盘接受靠近中心的点击,在这种情况下,10 偏移量足以 select 9。

我在 flutter 驱动程序测试中执行此操作,但该命令的实现是作为我自己的驱动程序扩展的一部分完成的,可以在您的集成测试中使用(您只需替换我的 prober 和你的 tester)

    final finder = find
        .ancestor(
            of: find.byKey(const ValueKey('time-picker-dial')),
            matching: find.byType(Listener))
        .first;
    // Wait for the time picker dialog
    await handlerFactory.waitForElement(finder).timeout(command.timeout!,
        onTimeout: () => throw ("Failed to find the time picker dialog"));
    final hoursAngleDeg = command.hours * 360 / 12;
    final minutesAngleDeg = command.minutes * 360 / 60;
    final center = prober.getCenter(finder);
    final topRight = prober.getTopRight(finder);
    final radius = topRight.dx - center.dx;
    final tapAtHours = Offset(
        center.dx + radius * cos((hoursAngleDeg - 90) * pi / 180),
        center.dy + radius * sin((hoursAngleDeg - 90) * pi / 180));
    final tapAtMinutes = Offset(
        center.dx + radius * cos((minutesAngleDeg - 90) * pi / 180),
        center.dy + radius * sin((minutesAngleDeg - 90) * pi / 180));
    await prober.tapAt(tapAtHours);
    await handlerFactory.waitForElement(finder).timeout(command.timeout!,
        onTimeout: () =>
            throw ("Failed to find the minutes time picker dialog"));
    await prober.tapAt(tapAtMinutes);