Xcode 7 UI Testing target locale and region settings
Asked Answered
A

2

9

I'm trying to set the language and the region of my UI Testing target, and unfortunately it doesn't seem to work.

I've tried both ways, first:

  • Product | Scheme | Edit Scheme
  • Run | Options
    • Application Language: French
    • Application Region: France
  • Test | Arguments
    • Use the Run action's arguments and environment variables: Checked

And I try this other way:

  • Product | Scheme | Edit Scheme
  • Test | Arguments
    • Use the Run action's arguments and environment variables: Unchecked
    • Arguments passed at launch:
      • -AppleLanguages (French)
      • -AppleLocale fr_FR

Each way resulting in the UI Testing still happening in English. Moreover, when I hit the record button, it runs in French...

So if I do something wrong, I would be happy to know!

Thanks in advance!

Airdrie answered 3/3, 2016 at 15:18 Comment(1)
Do you have figured it out? I have exactly the same problem. Even the simulator settings change has no effect :-(Postgraduate
P
14

I have figured it out. I set the locale settings in the launchArguments for testing temporary in Xcode.

override func setUp() {
    super.setUp()

    // Put setup code here. This method is called before the invocation of each test method in the class.

    // In UI tests it is usually best to stop immediately when a failure occurs.
    continueAfterFailure = false
    app = XCUIApplication()
    app.launchArguments = [
        "-inUITest",
        "-AppleLanguages",
        "(de)",
        "-AppleLocale",
        "de_DE"
    ]

For CI I use fastlane from Felix Krause and get localized screenshots with snapshot.

Postgraduate answered 2/4, 2016 at 6:42 Comment(4)
Woot! Thanks! I works, even if I do not understand why the target settings does not! (I also use Felix Krause's utils)Airdrie
One would think that scheme settings would do the job, but they don't. You, sir, are a hero!Risible
doesn't work for me sadly. At least using [NSLocale currentLocale].localeIdentifier in the target application. It ignores the launch arguments and instead reads the sim settings. Actually this ties up with another post "The arguments are actually passed to the test itself but not to the tested app". See #35463650 Also what Apple state in the WWDC video. It's only possible for the test runner bundle to interact with the app target via accessibility.Pismire
actually now I'm not so sure. Passing arguments in the UI Test target scheme settings works. But the equivalent as launchArguments in code is ignored. This contradicts behaviour described by developer.apple.com/library/content/documentation/MacOSX/…Pismire
M
1

Try changing the specs on the simulator. It worked for me every time.

On Simulator: Settings > General > Language & Region > iPhone Language --> change here

Matriculate answered 3/3, 2016 at 15:30 Comment(2)
Thank you, but unfortunately, there are two caveats to this method: when you reset the simulator, you loose your configuration, but most of all, it only works on simulators on your local machine. As it is for CI when it runs on Xcode server you don't access the simulators tests are run on.Airdrie
Sorry then, that was my only shot. Good luckMatriculate

© 2022 - 2024 — McMap. All rights reserved.