How To Add Launch Arguments & Environment values on iOS Extension In UI Automation Test

I've got a UIAutomation test that tests an app with a Share Extension. I want to pass in some launchArguments and launchEnvironment properties to the Share Extension in my test. I can't figure out a way of doing it. When debug the ProcessInfo in the extension my values aren't there. I've tried setting them like this:

XCUIApplication(bundleIdentifier:"com.my.app").launchArguments = ["TEST"]
XCUIApplication(bundleIdentifier:"com.my.app").launchEnvironment = ["TEST":"TEST"]

and this:

XCUIApplication().launchArguments = ["TEST"]
XCUIApplication().launchEnvironment = ["TEST":"TEST"]

Note, I am correctly getting the correct process when I'm finding it with the bundle identifier.

Replies

Launch arguments and the environment get passed to your XCUIApplication when it is launched. I'm not sure if you can call XCUIApplication().launch() on a share extension.

That said, you should be able to interact with the share extension with its accessibility elements using a UI test.

You should be able to manually set launch arguments and environment variables on a share extension from your scheme's "Run" settings- by setting the "Launch" setting in the "Info" tab to "Wait for the executable to be launched", then clicking the Run button in Xcode. Your extension won't be launched immediately, but when it is (either manually or in a UI test), it would use your arguments and environment variables.