Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

ios - Xcode 7 UITests with localized UI

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

[tabBarsQuery.buttons["particiants"] tap];

This works for English but fails for other languages.

[tabBarsQuery.buttons[NSLocalizedString("PARTICIPANTS",comment:nil)] tap];

Fails - probably because Localizable.strings is in another bundle. How can I test a localized app?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Option 1: Set a Default Language

Create a new scheme for UI Testing and set the default Application Language. This will lock the app into one localized file so you can write all of your tests for that language.

Set the option from Product -> Scheme -> Manage Schemes or ??,. Then select the Options tab and set the language.

Xcode - Set the Default Application Language

Pros: Simple, one-time change.

Cons: Cannot be used to create localized screenshots with snapshot (a tool that runs your app via UI Testing and generates App Store screenshots along the way).

Option 2: Use -accessibilityIdentifier for Localized Strings

Instead of accessing items via their displayed text or value, use accessibilityIdentifier. This is read by the UI Testing framework but never shown or read to users (even with accessibility turned on). In the old UIAutomation docs Apple mentions using this for developer functionality, which this seams like a good use case.

You can then continue to set accessibilityLabel and accessibilityValue like normal, with the localized versions.

Pros: Can be used for more generic solutions, such as taking automated screenshots.

Cons: Might require more work changing each label you need "unlocalized" for testing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...