Flutter驱动程序挂在初始屏幕上 [英] Flutter Driver hangs at splash screen

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

问题描述

我正在尝试为我的应用程序设置Flutter驱动程序测试,并且该应用程序异步运行,所以我找到了 https://github.com/flutter/flutter/issues/41029 ,其中指出了您需要做的所有事情要做的是添加 await driver.waitUntilFirstFrameRasterized(); ,它应该可以工作,尽管这样做确实可以阻止测试失败,但是根本无法运行.

该应用程序只是挂在初始屏幕上,甚至从未进入应用程序本身.

据我所知,这是我运行测试所需的全部设置

  FlutterDriver驱动程序;//在运行任何测试之前,请连接到Flutter驱动程序.setUpAll(()异步{驱动程序=等待FlutterDriver.connect();等待driver.waitUntilFirstFrameRasterized();//等待Directory('screenshots').create();});//测试完成后,关闭与驱动程序的连接.tearDownAll(()异步{if(driver!= null){等待driver.close();}}); 

但是,我在终端中得到的只是以下输出:

  VMServiceFlutterDriver:通过以下网址连接到Flutter应用程序:http://127.0.0.1:54264/tt9kN4jBSrc=/VMServiceFlutterDriver:隔离编号为2942164624858163VMServiceFlutterDriver:隔离在启动时暂停.VMServiceFlutterDriver:尝试恢复隔离VMServiceFlutterDriver:已连接到Flutter应用程序.VMServiceFlutterDriver:waitForCondition消息需要很长时间才能完成... 

我已经离开它几分钟了,什么也没发生,我已经禁用了Firebase初始化,以防万一某种原因阻止了它,因为我需要接受警报对话框,而不是我能看到的那么远./p>

解决方案

结果我也需要使用 IsolatesWorkaround

  FlutterDriver驱动程序;IsolatesWorkaround解决方法;//在运行任何测试之前,请连接到Flutter驱动程序.setUpAll(()异步{驱动程序=等待FlutterDriver.connect();解决方法= IsolatesWorkaround(driver);等待解决方法.resumeIsolates();等待driver.waitUntilFirstFrameRasterized();如果(!await Directory('screenshots').exists()){等待Directory('screenshots').create();}});//测试完成后,关闭与驱动程序的连接.tearDownAll(()异步{等待驱动程序吗?.close();等待workaround.tearDown();}); 

请参阅: https://gist.github.com/vishna/03c5d5e8eb14c5e567256782cddce8b4 >

I am trying to setup Flutter Driver tests for my application and the app runs async so I found https://github.com/flutter/flutter/issues/41029 which says all you need to do is add await driver.waitUntilFirstFrameRasterized(); and it should work, while this does stop the test from failing it nos simply does not run.

The app just hangs at the splash screen never even getting into the application itself.

As far as I am understanding, this is all I would need to have setup in order for the test to run

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

    // await Directory('screenshots').create();
  });

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

However, all I am getting in my terminal is the following output:

VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:54264/tt9kN4jBSrc=/
VMServiceFlutterDriver: Isolate found with number: 2942164624858163
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
VMServiceFlutterDriver: Connected to Flutter application.
VMServiceFlutterDriver: waitForCondition message is taking a long time to complete...

I have left it for minutes and nothing happens, I have disabled the firebase initialization in case somehow that is blocking it as I would need to accept the alert dialogue, not that I am even getting that far as I can see.

解决方案

Turns out I needed to use an IsolatesWorkaround as well

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

    if (!await Directory('screenshots').exists()) {
      await Directory('screenshots').create();
    }
  });

  // Close the connection to the driver after the tests have completed.
  tearDownAll(() async {
    await driver?.close();
    await workaround.tearDown();
  });

See: https://gist.github.com/vishna/03c5d5e8eb14c5e567256782cddce8b4

这篇关于Flutter驱动程序挂在初始屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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