Issue
I'm writing UI Automation tests for an Android app using Espresso. The test will search for a barcode number and find the associated item, but this feature is only available to US users. The users market is identified by the device language (en_US, en_UK).
How can I write this test so that it won't fail every time I run the automated tests for the UK?
I accomplished this with XCTest for the iOS app by creating a method that checks the devices current language.
class MarketChecker: XCTestCase {
func isUSLocale() -> Bool {
return Locale.current.identifier == "en_US"
}
func isGBLocale() -> Bool {
return Locale.current.identifier == "en_GB"
}
}
The method is then called at the start of the test:
if isUSLocale() {
<US specific test>
}
This allows me to run the same test suite without having failures caused by our apps regional differences.
Unfortunately (for me) Espresso does not like if statements so I'm not sure how to implement this for the Android app. Any insights would be hugely appreciated!
Solution
Managed to figure it out. This is useful if your app is in multiple markets controlled by the device language.
public static String deviceLocale() {
return Locale.getDefault().getCountry();
}
public static boolean isGBLocale() {
return deviceLocale().equals("GB");
}
public static boolean isAULocale() {
return deviceLocale().equals("AU");
}
public static boolean isUSLocale() {
return deviceLocale().equals("US");
}
This can be used to validate market specific differences or skip tests that would otherwise fail in that market.
if (isUSLocale()) {
// US test
}
Answered By - Stephen Mehrer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.