How to access launchEnvironment and launchArguments set in XCUIApplication, running UI tests in XCode?

If you set launchArguments in a UI Test (Swift):

let app = XCUIApplication()
app.launchArguments.append("SNAPSHOT")
app.launch()

Then read them in your App using:

swift 2.x:

if NSProcessInfo.processInfo().arguments.contains("SNAPSHOT") {
   // Do snapshot setup
}

Swift 3.0

if ProcessInfo.processInfo.arguments.contains("SNAPSHOT") {
}

To set environment variables, use launchEnvironment and NSProcessInfo.processInfo().environment, respectively, instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)