Xcode 7 UITests with localized UI

后端 未结 11 932
既然无缘
既然无缘 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 17:48

    Objective-C Solution : inspired by @Volodymyr Prysiazhniuk solution

    - (NSString*)getLocalizedStringForKey :(NSString*)stringKey forUITestClass : (id) uiTestClass{
        if (!stringKey || !uiTestClass){
            return nil;
        }
        NSString *bundlePath = [[NSBundle bundleForClass: uiTestClass]bundlePath];
        NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
        NSString* localizedString = NSLocalizedStringWithDefaultValue(stringKey, nil, bundle, nil, nil);
        return localizedString;
    }
    

提交回复
热议问题