Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

Multi Language Support

Pratik_ShahPratik_Shah Moderators
edited August 14 in Sahi Pro
Yesterday, few of my friends and I were having a coffee and one of my friends started complaining about his work. He works for a web application development company where the application is used across the globe with different languages. He was given the task to test the application on all available languages. He had to deal with many languages and they can add any language at any given time. He recorded the script in one language and the same won't work on any other language as the string will not be the same.

My another friend, who also had faced the same issue jumped into the discussion, saying we have created automated tests using Sahi Pro and currently we test only in English as the scripts were recorded in English and we can not rework for all the languages.

I somewhat agreed with what he was saying but at the same time, testing on all the available languages was also important. That motivated me to write an article which will help people facing the similar issue. I knew Sahi Pro is the tool which provides Multi Language Support.

Let's take google.com as an example to understand the concept. Now,

1. We have the application which supports multi language - google.com
2. We have the tool which supports the localization testing - Sahi Pro

Now, let see how it actually works.

In most applications, Internationalization (I18N) and Localization (L10N) are done by specifying constant keys in web application code, and then having another layer substitute these constant keys with the correct language translations provided via property files.
These translations are normally stored in properties files. Eg. en.properties (english), hindi.properties (hindi) etc.

I recorded the script on Google English and here it is.

_navigateTo("https://www.google.co.in ");
_assertVisible(_submit("Google Search"));
_click(_link("Google apps"));
_assertVisible(_span("My Account"));
_click(_link("Sign in"));
_setValue(_emailbox("identifier"), "shah.pratik123");
_click(_div("Next"));

and the logs of the script execution.


d9qvqu2loj27.jpg

As mentioned above, you would need language.properties file for localization/internationalization testing. Ideally, these property files should already be present with the developers. Here, unfortunately, I am not a Google Developer, hence I had to create these properties files. I will use hindi.properties file and en.properties file. The content of these files are as following:

1) hindi.properties
GOOGLE_SEARCH=Google खोज
GOOGLE_APPS=Google ऐप्लिकेशन
MY_ACCOUNT=मेरा खाता
SIGN_IN=प्रवेश
BTN_NEXT=आगे
BTN_SIGN_IN=प्रवेश करें

2) english.properties
GOOGLE_SEARCH=Google Search
GOOGLE_APPS=Google apps
MY_ACCOUNT=My Account
SIGN_IN=Sign in
BTN_NEXT=Next
BTN_SIGN_IN=Sign in


Now, I will modify the above-recorded script a little bit for Multi Language Support. Sahi Pro uses _setLanguage() API to translate the languages. I want the same recorded script to be executed in Hindi Language.
_navigateTo("https://www.google.co.in ");
_click(_link("हिन्दी"))
_setLanguage("hindi.properties", "en.properties");
_assertVisible(_submit("Google Search"));
_click(_link("Google apps"));
_assertVisible(_span("My Account"));
_click(_link("Sign in"));
_setValue(_emailbox("identifier"), "a@example.com");
_click(_submit("Next"));
_setValue(_password("Passwd"), "aa");
_assertVisible(_submit("K:BTN_SIGN_IN"));

Here, I had to click on हिन्दी link, so that Google will show the page in Hindi. You just need to launch the URL of your application which is in a different language.

The logs of this script execution are as follows:

b8sca5nthvxy.jpg



Let's see how it works. It will navigate to the google.com and click on the Hindi link so that the content will be converted to Hindi language. Our script makes use of the English words as it was earlier recorded for English.

We are using _setLanguage() API to translate the language from English to Hindi.

All the strings will be first picked up. In here, the first string after the _setLanguage() is "Google Search" , it will be looked in the english.properties file and it will find the key for that string. In this case, the key is GOOGLE_SEARCH . Now GOOGLE_SEARCH will be searched in the hindi.properties as a key and against this key, the value will be determined i.e Google खोज and the statement will be created from

_assertVisible(_submit("Google Search"));

to

_assertVisible(_submit("Google खोज"))

It will perform the same action for the rest of them. There are other keywords like 'L' for literals 'K' for Keywords.

You can find more information on this at http://sahipro.com/docs/sahi-apis/multi-language.html#_setLanguage

Hope this helps.



Sign In or Register to comment.