【问题标题】:Grant iOS permissions to Flutter Driver for integration test将 iOS 权限授予 Flutter Driver 以进行集成测试
【发布时间】:2021-06-05 10:25:10
【问题描述】:

使用 Flutter integration_test 包时,由于测试环境无法访问 iOS 权限请求,我遇到了测试不断失败的问题。

我从github.com/wix/AppleSimulatorUtils 尝试了applesimutils,但是尝试在flutter drive 之前设置权限时,应用程序的捆绑标识符尚未注册:

Got error:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
The operation couldn’t be completed. No such file or directory
No such file or directory

也许这可以通过不每次都创建一个新的 Simulator 实例来避免,但我通过在 applesimutils --setPermissions 命令之前运行 flutter drive ... & sleep 10 以允许应用程序首先启动来解决这个问题,但这仍然给了我:

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following LocationError object was thrown running a test:
  [LocationError code: 0, message: null]

When the exception was thrown, this was the stack:
#2   BackgroundGeolocation.getCurrentPosition.<anonymous closure>
  (package:flutter_background_geolocation/models/background_geolocation.dart:497:17)

...

【问题讨论】:

    标签: flutter flutter-test location-services ios-permissions flutterdriver


    【解决方案1】:

    在熟悉了xcrun simctl 之后,我注意到它可以在应用程序启动之前授予权限,只要设备已经启动。 applesimutils 不需要!

    我的 shell 脚本形式的工作解决方案如下所示:

    # Simulator setup
    xcrun simctl create iOS14Simulator
    xcrun simctl boot iOS14Simulator
    xcrun simctl privacy iOS14Simulator grant location-always <YOUR_BUNDLE_ID>
    
    # Launch integration test
    flutter drive \
      --driver=test_driver/integration_test_driver.dart \
      --target=integration_test/app_test.dart
    
    # Simulator teardown
    xcrun simctl delete iOS14Simulator
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-21
      • 2021-11-13
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      相关资源
      最近更新 更多