Pass dictionary as a value to launchArguments for UI Tests

170 Views Asked by At

I am trying to pass a value represented as a dictionary for launchArguments in order to run UI Tests.

So, I have tried to convert the dictionary to a String format and pass it like that:

let dic = ["Key1": "Value1", "Key2": "Value2"]
do {
    let data = try JSONEncoder().encode(dic)
    if let value = String(data: data, encoding: .utf8) {
        launchArguments += [ "-launchKey", value ]
    }
} catch {
    print("Error encoding launchArguments: \(error.localizedDescription)")
}

When the app starts, it doesn't add a dictionary to UserDefaults. It doesn't give any information as well. What might be a problem?

1

There are 1 best solutions below

0
Kaan Sariveli On

launchArguments is array of string: https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments

launchEnvironment is a dictionary: https://developer.apple.com/documentation/xctest/xcuiapplication/1500427-launchenvironment

you can access launchEnvironment key: ProcessInfo.processInfo.environment["yourKey"]