Xcode 7 UITests with localized UI

后端 未结 11 930
既然无缘
既然无缘 2020-12-07 17:38

In my App I\'m using NSLocalizedString to localize my app. Now I want to switch to UITests and habe Testcode like this:

[tabBarsQue         


        
11条回答
  •  离开以前
    2020-12-07 18:01

    I've made localized screenshots with Fastlane using next scheme:

    1) Add to Fastfile next param:

    localize_simulator: true

    2) Use this code to get localized string:

    class LocalizationHelper: NSObject {
    
        class func localizedString(_ key: String) -> String {
            let testBundle = Bundle(for: UITests.self)
            let currentLocale = Locale.current
            if let code = currentLocale.languageCode,
                let testBundlePath = testBundle.path(forResource: code, ofType: "lproj") ?? testBundle.path(forResource: code, ofType: "lproj"), let localizedBundle = Bundle(path: testBundlePath) {
                return NSLocalizedString(key, bundle: localizedBundle, comment: "")
            }
            return ""
        }
    
    }
    

提交回复
热议问题