swiftxcodexcode-ui-testinginfo.plist

How to use info.plist in Xcode UITest target?


I have a project with iOS app and UITests targets. UITest target has its own info.plist, and I tried to add additional row: info.plist in UITest target

But during tests executing new row is unavailable in code:

(lldb) po Bundle.main.infoDictionary!["EMAIL"]
nil
(lldb) po Bundle.main.object(forInfoDictionaryKey: "EMAIL")
nil

In Xcode since version 13 info.plist doesn't create as separate file. But after adding new row I found a new one in the project tree, and it contain my row only without other rows that were added as default. In build settings I removed generating of info.plist. After that file contains all rows. But in both cases my row is unavailable. Are info.plist settings even available in UITest targets? Or I should take them some other way? Maybe UITest should call some other bundle, not main like 'Bundle.main'?

Upd: I found that one of bundles already contains necessary value:

if let bundle = Bundle.allBundles.first(where: { $0.object(forInfoDictionaryKey: "EMAIL") is String }),
   let email = bundle.object(forInfoDictionaryKey: "EMAIL") as? String {
    print(email) // it works
}

So, in Xcode UITests we should use some other bundle, not main. But what exactly?


Solution

  • Do you try to get your UITest's target bundle?

    For example:

    func getEmail() -> String?  {
        let bundle = Bundle(for: type(of: self))
        let email = bundle.object(forInfoDictionaryKey: "EMAIL") as? String {
            return email
        }
        return nil
    }