Skip to content

Commit

Permalink
TECH: fix bug with locales in docloc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sumin93 committed May 17, 2023
1 parent 3d6ee09 commit 587653e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kaspersky.kaspresso.device.languages

import androidx.annotation.MainThread
import java.util.Locale

/**
Expand All @@ -10,10 +11,11 @@ interface Language {
/**
* Switches language only in the current Application (not in OS!).
* Please, keep in mind the following fact:
* If you have switched languages then you need to refresh current screen to get the screen with new language!
* If you have switched languages then activity.recreate() invoked so you have to do it on MainThread only
* Also, don't forget to restore the previous language if you don't clean the state of the Application after each test.
*
* @throws Throwable if something went wrong
*/
@MainThread
fun switchInApp(locale: Locale)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class DeviceLanguageSampleTest : TestCase() {
device.targetContext.resources.configuration.locale
}
}.after {
device.language.switchInApp(default)
activityRule.scenario.onActivity {
// it's so important to call this method on main thread
device.language.switchInApp(default)
}
}.run {

step("Change locale to english") {
device.language.switchInApp(Locale.ENGLISH)
// it's so important to reload current active Activity
// you can do it recreating the activity or manipulating in the Application through great Kaspresso
activityRule.scenario.onActivity { activity ->
activity.recreate()
activityRule.scenario.onActivity {
// it's so important to call this method on main thread
device.language.switchInApp(Locale.ENGLISH)
}
Thread.sleep(SLEEP_TIME)
}
Expand All @@ -60,11 +60,9 @@ class DeviceLanguageSampleTest : TestCase() {
}

step("Change locale to russian") {
device.language.switchInApp(Locale("ru"))
// it's so important to reload current active Activity
// you can do it recreating the activity or manipulating in the Application through great Kaspresso
activityRule.scenario.onActivity { activity ->
activity.recreate()
activityRule.scenario.onActivity {
// it's so important to call this method on main thread
device.language.switchInApp(Locale("ru"))
}
Thread.sleep(SLEEP_TIME)
}
Expand Down

0 comments on commit 587653e

Please sign in to comment.