Many applications are designed for use in different countries, with different languages. Such applications usually allow switching between application languages, so that all the writings, headings, and other interface elements are displayed in the local language. More often than not, the functionality of the application as a whole is not subject to change; therefore, there is no sense in carrying out functional or regression testing for all the localized versions. Sometimes, however, the application should comply with more stringent requirements, in which case it becomes necessary to launch all the tests (or at least some of them) for all the available languages.
In this recipe, we will learn to work with multilingual application in such a way that the scripts code remains intact as we make it possible to easily switch between the languages of the tested application. Let's suppose we need to create such a possibility for a standard application of Notepad that is a part of the Windows suite.
We need to perform several preparation steps before start:
In order to create a test for multilingual application, we need to perform the following actions:
function testMultilanguageApp() { var notepad; var wndNotepad; var dlgFind; var btnFindNext; notepad = Aliases.notepad; wndNotepad = notepad.wndNotepad; wndNotepad.Edit.Keys("Some text^[Home]"); wndNotepad.MainMenu.Click("Edit|Find..."); dlgFind = notepad.dlgFind; dlgFind.Edit.SetText("text"); btnFindNext = dlgFind.btnFindNext; btnFindNext.ClickButton(); dlgFind.btnCancel.ClickButton(); }
You will have Configuration Manager window opened with one configuration (Default Configuration).
var menuEng = { Edit: "Edit", EditFind: "Edit|Find..." }; var menuRus = { Edit: "Правка", EditFind: "Правка|Найти..." };
function testMultilanguageApp() { var menu = menuRus; var notepad; var wndNotepad; var dlgFind; var btnFindNext; notepad = Aliases.notepad; wndNotepad = notepad.wndNotepad; wndNotepad.Edit.Keys("Some text^[Home]"); wndNotepad.MainMenu.Click(menu.EditFind); dlgFind = notepad.dlgFind; dlgFind.Edit.SetText("text"); btnFindNext = dlgFind.btnFindNext; btnFindNext.ClickButton(); dlgFind.btnCancel.ClickButton(); }
NameMapping can contain as many configurations as possible, each one corresponding to the languages of the tested application. Perhaps the most difficult aspect of handling such applications is manual renaming of all the properties of all the elements used in NameMapping; however, this should be done just once. In order to launch the scripts for another application language, it is sufficient to change the current configuration on the NameMapping panel, and have the possibility to quickly change the language that is being used for the menu (both for the main and all other contextual menus of the application that are evoked by the right-click). In our case, we have decided to form up the elements of the main menu as objects.
A more successful solution for information storage would be the usage of data-driven approach. This would allow inputting all the data on the menu into separate files with tables (for example, each language would match individual Excel files). Implementation of such an approach, however, would be overkill for the given recipe.
Changing configurations for the NameMapping element is possible not only from the TestComplete window, rather directly from the script code. To this end, it is necessary to set the required value for the CurrentConfigurationName property property of the NameMapping
object. For example, switching the Russian configuration on would have the following effect:
NameMapping.CurrentConfigurationName = "Russian";
NameMapping
and Aliases
are working, refer to the article at http://support.smartbear.com/viewarticle/27370/.18.223.172.132