Using the Flutter integration_test
package, I'm having trouble with a test that keeps failing due to an iOS permissions request that is inaccessible from the testing environment.
I tried applesimutils
from github.com/wix/AppleSimulatorUtils but when attempting to set the permissions before flutter drive, the application's bundle identifier isn't yet registered:
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
Maybe this could be avoided by not creating a fresh Simulator instance every time, but I got past this by running flutter drive ... & sleep 10
before the applesimutils --setPermissions
command to allow the application to start first, but that still gives me:
══╡ 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)
...
After getting a bit more familiar with xcrun simctl
I noticed that it can grant permissions before the application starts, as long as device has booted. applesimutils
not required!
My working solution in the form of a shell script looks like this:
# 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