Localization Tests in UI Testing

Hi


The app under test is localized and internationalized. So when device language is changed, strings displayed on the app are changed.


I am trying to write test cases that work independent of the current language, in order to achieve this some of the static text/button labels have to be localized for the element query to work correctly.


How can we achieve this? If I try to have all the strings in an external file, the bundle created for UITesting for some reason does NOT include this strings file.


Can someone please shed light on how to include non-code files into UI Testing bundle?


I tried having the file named as .json, .strings. It does not work.


Thanks

Naveen

Hey. You can go into the Scheme Editor of the test scheme under Options, and change App Region/Language to one you prefer, and that will be independent of your current device language.

Hope this helps.

Hello!

The recommended way to UI test a localized app is by using accessibility identifiers, not strings, as a way to uniquely target elements.

Accessibility identifiers can be unique per element and are not localized. For instance, XCUIApplication().buttons["Hello"] might change in each locale, since "Hello" is an English string.

XCUIApplication().buttons["HELLO_ID"] would not change in each locale.

You can set the accessibility identifier on a button (for example) using its accessibilityIdentifier property: https://developer.apple.com/documentation/uikit/uiaccessibilityidentification/1623132-accessibilityidentifier

Localization Tests in UI Testing
 
 
Q