-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add a possibility to set app locale #580
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check RTL, too. Will update our demo app for it to check.
} | ||
val res = context.resources | ||
val config = res.configuration | ||
config.locales = LocaleList(locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config.setLayoutDirection(locale)
is necessary to apply RTL style properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring on setLocales method:
/**
* Set the locale list. This is the preferred way for setting up the locales (instead of using
* the direct accessor or {@link #setLocale(Locale)}). This will also set the layout direction
* according to the first locale in the list.
*
* Note that the layout direction will always come from the first locale in the locale list,
* even if the locale is not supported by the resources (the resources may only support
* another locale further down the list which has a different direction).
*
* @param locales The locale list. If null, an empty LocaleList will be assigned.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, okay. I see.
I also understand this is application-wide change (via the target context), so other areas such as status bar and other applications do not change.
Will check with an app which has multiple locale/layout later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocaleList is only for API level 24. (below is for lower versions)
config.locale = locale
config.setLayoutDirection(locale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, will change
@@ -41,7 +41,7 @@ let espressoCapConstraints = { | |||
activityOptions: { | |||
isObject: true | |||
}, | |||
locale: { | |||
appLocale: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
How did you check this feature? But the locale (displayed language) did not change by this via mobile command even only application-wide. |
I tried Android 8. I suppose you have to restart the activity or start a new one/restart the current to have the changes applied to the UI. |
Thanks. Even we provide appLocale capability, the initial activity does not have the appLocale one. We should apply the locale change before starting the app under test's process to apply this from the beginning. In Espresso case, I imagine applying this change in |
Yes, this is something I was getting as well. And this is strange, because I actually set the stuff before starting the activity |
Added some methods to restart the activity after locale change. Perhaps, it could make it working |
I have Android 6 and Android 10 devices. But no luck for Android 10 even I did the same steps with Android 6. I mean both via capabilities and mobile command. I needed to kill the activity once and launch them again by manual. |
thanks for your help |
Let me know if you have any ideas regarding the code modification |
You were right @KazuCocoa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I checked this method worked on my phone, too.
I think this way, leaving only the capability, is the best enough way for us (as espresso-driver)
The Espresso approach depends on the app under test's implementation.
So, generally, users should decide if follow this application-wide method or system-wide (by settings app, but hacky one) in their tests
} | ||
return null | ||
} | ||
for (method in listOf(method1, method2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Locale.setDefault(Locale.Category.DISPLAY, locale) | ||
} | ||
|
||
if (SDK_INT >= Build.VERSION_CODES.N) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Currently it is only possible to set locale via Appium Settings helper, which does it in a really hacky manner. Also there is no guarantee this hack going to work in newer Android versions.
Although, Espresso anyway uses the target context concept, which we could change locale for without private method calls. I've added the
locale
capability that allows to set locale for an initial app startup as well asmobile: setLocale
one, which does it dynamically.I would really appreciate it if you could help me with testing on newer Android versions @KazuCocoa