0

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

applesimutilsgithub.com/wix/AppleSimulatorUtils尝试过,但是在尝试在颤动驱动器之前设置权限时,应用程序的包标识符尚未注册:

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 实例来避免这种情况,但是我通过在命令flutter drive ... & sleep 10之前运行applesimutils --setPermissions以允许应用程序首先启动来解决这个问题,但这仍然给了我:

══╡ 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)

...
4

1 回答 1

0

在熟悉了一些之后,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
于 2021-03-07T08:31:00.207 回答