Search code examples
iosswiftxctestui-testing

XCTest cannot read launch arguments


I am running a UI test and in the setUp() method I set a launch argument:

self.app = XCUIApplication()
self.app.launch()        
self.app.launchArguments.append("UITesting")

Then later in the testI try to read the launch argument this way:

if ProcessInfo.processInfo.arguments.contains("UITesting") {
    // do something
}

But the code inside the if is never executed. How to make it work?


Solution

  • You cannot set launch arguments after the app is already launched.

    You shall set the launch arguments and environment variables, and then launch the app

        app.launchArguments.append("UITesting")
        app.launch()