在iOS上无法在对话框中点击允许按钮的Flutter集成测试。任何人都可以帮助完成这项工作?
flutter - Flutter集成测试,无法在对话框中点击对话框中的“允许”按钮-LMLPHP

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

Future<void> delay([int milliseconds = 250]) async {
  await Future<void>.delayed(Duration(milliseconds: milliseconds));
}

void main() {
  group('My App', () {

    FlutterDriver driver;

    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    // Close the connection to the driver after the tests have completed.
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });



     test('Allow Notification', () async {
        SerializableFinder appBarTitle = find.text("Happy");
        await driver.waitFor(appBarTitle);
        // await delay(3000); // for video capture
        expect(await driver.getText(appBarTitle), isNotEmpty);
     });

  });
}

最佳答案

我希望我的发现能够帮助某人。
我收到错误“DriverError:由于远程错误而无法执行Tap”和“VMServiceFlutterDriver:tap消息花费很长时间才能完成。”
就我而言,Flutter Driver无法找到要测试的小部件,因为我使用的是“find.byType”。
一次,我为所有小部件都指定了“键”,并传递给使用“find.byValueKey”而不是“find.byType”,这些小部件已本地化,并且一切正常。
那就是我的代码:

void main() {
  group('reversor app integration test', () {
    FlutterDriver driver;

    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    tearDownAll(() {
      if (driver != null) {
        driver.close();
      }
    });

    // find.byType was the cause for the error 'DriverError: Failed to fulfill Tap due to remote error'
    // Given key for the three below widgets, and after hat using 'find.byValueKey', solved the problem
    var field = find.byValueKey("TextField");
    var btn = find.byValueKey("button");
    var reverse = find.byValueKey("response");

    test('Reversing the string', () async {
      await driver.clearTimeline();
      await driver.tap(field);
      await driver.enterText("Hello222");
      await driver.waitForAbsent(reverse);
      await driver.tap(btn);
      await driver.waitFor(reverse);
      await driver.waitUntilNoTransientCallbacks();
      assert(reverse != null);
    });
  });
}

关于flutter - Flutter集成测试,无法在对话框中点击对话框中的“允许”按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60690462/

10-12 14:34