fastlane-old/snapshot

Device locale not changed to match language

stonehouse opened this issue · 9 comments

I apologise in advance if I've missed something in the documentation, but I spent quite a lot of time trying to get localised screenshots working properly without success. Basically, the app changes language flawlessly, but the locale/language of the simulator doesn't match. This is mainly a problem because the app involves text entry. This means that, for example, German screenshots have red underlined text because its applying English validation.

I've tried several different combinations of configuration without luck, as well as manually setting the language in the simulator beforehand.

languages(["de-DE"])
languages(["de_DE"])
languages(["de"])
languages([["de", "de-DE"]])

I've additionally tried working with the launch arguments

launch_arguments(["-AppleLanguages (de)", "-AppleLocale de-DE"])

Any support would be greatly appreciated. Cheers

Could you share your complete UI Test file?

Sure thing, I went ahead and created a new project to test the issue as a sanity check. If you look at the screenshot below you can see what I mean. All the codes there, let me know if I can help.

func testEnterText() {
        let text = "Test text entry in English. Jetzt Texteingabe auf Deutsch. Sacré bleu, Omelet du Fromage"

        let app = XCUIApplication()
        let inputTextView = app.textViews["Input"]
        inputTextView.tap()
        inputTextView.typeText(text)
        snapshot("Localization0")
    }
languages([
  "en-US",
  "de-DE",
  "fr-FR"
])

https://github.com/egosapien/SnapshotLocalizationProblem

https://github.com/egosapien/SnapshotLocalizationProblem/blob/master/fastlane/screenshots/de-DE/iPhone6-Localization0.png

I don't believe it's possible to set the language of the simulator (see #365 (comment)). Perhaps you can work around it by disabling spelling corrections?

I wonder if the fix for #437 may also fix this.
@egosapien could you try updating the SnapshotHelper.swift to replace the setLanguage with

    class func setLanguage(app: XCUIApplication) {
        let path = "/tmp/language.txt"

        do {
            let input = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String

            deviceLanguage = input
            locale = input

            app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))", "-AppleLocale", "\"\(locale)\"","-ui_testing"]
        } catch {
            print("Couldn't detect/set language...")
        }
    }

@egosapien could you try with the latest snapshot? I just released an updated version with #437 which improves locale and language handling.

@i2amsam I've just tried the latest version, and I have the same issue. As I mentioned in the beginning I also tried using the AppleLocale start parameter. It doesn't seem to make any difference to the simulator's locale. Or at least it has no effect on the keyboard.

My thought at the moment is to either write some debug only code to dismiss the keyboard and deactivate validation or add a UITest helper to change the keyboard. The latter is definitely preferable but I'm worried about how reliable it will be.

same issue for me! :( langs doesn't changed..

Hmm. It works for my first target, but doesn't work for another!
I tried to remove all fastlane folder and init it for second project from the scratch, but still got this error. Please, let me know, if you need any additional details.

This issue was migrated to fastlane/fastlane#1643. Please post all further comments there.

fastlane is now a mono repo, you can read more about the change in our blog post. All tools are now available in the fastlane main repo 🚀