Localization testing for Android

Hi,

Can anyone help me to explain how localization testing is performed using Appium?

Regards
Gowri Kumar

We use a strings map our developers provide to localize our code. While we prefer to find objects by resource-ids, sometimes it’s not possible. In that case, we find the object by name (text), having provided the localized string to the appium call.

1 Like

can u pls share some code details

You can unpack the file with apktool, which you’ll likely have to download and install.

If you have a package, foo.apk, then when you unpack it, there will be a directory foo. Inside foo/res/values, you’ll find strings.xml, which will look something like this:

version_string-signed/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="common_android_wear_update_title">Update Android Wear</string>

The string name, common_android_wear_update_title, will be present in all the various strings.## directories, where “##” represents the two letter abbreviations for each language. Depending upon your language, you’ll just need to access the right language file.

It was relatively simple to find code on the net to parse this file: http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash

There are a few gotchas – Android strings files can have multiple entries for the same string based on whether it’s single or multiple, or in case of some languages, zero, so you’ll need to handle that. Also, when your app is compiled, it has some heuristic for when it escapes certain characters, so I had to write code to fix that. There are also html characters you’ll have to handle.

Good luck

1 Like

can i use language capability instead of above method

My requirement is my test app supports 14 different languages & we have to automate using appium for localisation testing

I believe the language capability allows you to set the language on your device. But if you need to verify the strings are correct, what are you going to verify it against?

thats true. I need to get string.xml file from developer. But even after setting capabilities app is launching in english only . could u pls suggest

You don’t need the source code – apktool will unpack the apk and give you access to the strings file(s).

As I said, we don’t use the language capability – we start up android settings via adb on the language settings page and automatically select the desired language.

i am using perfecto mobile +appium .

and

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(“language”, “pt”);

This was posted recently on this discussion board. Perhaps it will help you, @Tanushree_Bal

Hi willosser,
Thanks for u r response. If i am saving localisstion strings in a properties file can you please tell me how to use in scripting

@Tanushree_Bal, I tried to above: Localization testing for Android

If there is a part you didn’t understand, please let me know so I can clarify

In addition to using the language capability, to change the language of the application, we could use the getAppStrings method from the AppiumDriver class.

The getAppStrings method returns a map of key value pairs as mentioned in the strings.xml for the current selected language.

Hi Willosser ,

Thanks for all your response .

Could you please help me for below details

My Approach

  1. My Test App is supporting 14 different languages. We decided to get all the strings values details from the developers & maintain them in 14 different properties file .
  2. We are approaching page object model.
  3. And we are thinking to create 14 different class files for 14 different languages & Each class will contain all the elements & functionalties of all the screens of the app.
  4. And 14 different test java file call those class files by creating object of those class files to validate the localisation strings & functionalities like click to navigate to next screen as we are maintaining 1 screen class for 1 language for all the screens of the app.

And also we wanted to we have to write 14 different functions to load the properties file or a single function to load all the properties file

And also if our approach is not correct could you please guide us with the appropriate approach

@Tanushree_Bal,

I’m sorry, but your description has confused me. Let’s define the problem.

What you have:

  • 14 different languages supported by your product
  • Access to the languages files from the developers
  • Test software designed around the page object model

What you want:

  • Localization testing, which is…
    ** Validating the strings on the screen when the device language has been changed, or
    ** Something else?

If it’s the former, there are two ways to solve this problem using a script that walks through all screens

  1. Go to a screen, record everything, change the language settings to each of the 14 languages, and validate each item on the screen.
  2. Go through all screens, recording everything in one language, repeat for each language.

Android does the language translation for you automatically. It might be easier just to validate the language files are all correct. Whether you choose this route or want to take the screenshots, it will be necessary for you to understand the structure of the language files. The all take the form for key -> value, where key the keys are the same in each language file, and the values are localized strings. Instead of creating a separate class file for each language (all of which will be the same and hard-coded, which leads to fragile software), I’d suggest reading the original strings.xml files into a data structure that you can access by language and key, allowing you to compare all values.

Thanks Willosser for your response. Our requirement is same as u mentioned. We will try as per your guidelines using string.xml & update you if we need more support . Thanks for your help

Hey guys,

Any suggestions to set language on a real-time device through java? I did see android package. However, the project must be an android project than java project.

Hi Willosser ,

I have tried using language capability of appium . But test device is not booting as per the language capability .

Appium console errror

Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 22 --automation-name Appium --log-no-color
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {“address”:“127.0.0.1”,“logNoColors”:true,“platformName”:“Android”,“platformVersion”:“22”,“automationName”:“Appium”}
info: Console LogLevel: debug
info: → POST /wd/hub/session {“desiredCapabilities”:{“newCommandTimeout”:“120”,“platformVersion”:“5.1.1”,“app”:“C:\IHG Project\Rewards-playStore-staging.apk”,“platformName”:“Android”,“deviceName”:“Redmi”,“browserName”:“”,“appActivity”:“com.ihg.apps.android.SplashActivity”,“appium-version”:“1.4.0.0”,“language”:“FR”,“appPackage”:“com.ihg.apps.android”}}
info: Client User-Agent string: Apache-HttpClient/4.5.2 (Java/1.7.0_79)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : appium-version
info: [debug] Using local app from desired caps: C:\IHG Project\Rewards-playStore-staging.apk
info: [debug] Creating new appium session e42166ad-b4b9-408b-9a8e-3e16542767f9
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.7.0_79
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Program Files\Android SDK\platform-tools\adb.exe
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop persist.sys.language”
info: [debug] Current device persist.sys.language: it
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop persist.sys.country”
info: [debug] Current device persist.sys.country: FR
info: [debug] Setting Android Device Language to FR
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “setprop persist.sys.language fr;”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “stop; sleep 2; setprop sys.boot_completed 0; start”
info: [debug] waiting for reboot, this takes time.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] still waiting for reboot.
info: [debug] executing cmd: “C:\Program Files\Android SDK\platform-tools\adb.exe” shell “getprop sys.boot_completed”
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
warn: UiAutomator did not shut down fast enough, calling it gone
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: device didn’t reboot within 90 seconds
info: [debug] Error: device didn’t reboot within 90 seconds
at [object Object].fn (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1683:30)
at Object.async.until (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:704:13)
at [object Object]._onTimeout (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:708:23)
at Timer.listOnTimeout (timers.js:119:15)
info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: device didn’t reboot within 90 seconds)”,“origValue”:“device didn’t reboot within 90 seconds”},“sessionId”:null}

info: ← POST /wd/hub/session 500 114472.278 ms - 198

Can you please guide me further.

Hi @Tanushree_Bal,

I wish I had some recommendation for you. We wrote our language code ourselves. I haven’t used Appium’s capabilities for the same.

@willosser, hi currently I am doing android app automation, in this app i have option change to differnt language and I have string. Xml file for different languages text,

Kindly need sample code for string. Xml how to read different languages text pass to xpath

Please share sample code or any guidence. I am using jave.

Thanks.