Testing multilingual applications

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.

Getting ready

We need to perform several preparation steps before start:

  1. Add the Name Mapping element to the project (right-click on the name of the project, go to Add | New Item, then click on NameMapping).
  2. Make sure the automatic short names generation option has been enabled or enable it by going to Tools | Options..., then Engines | NameMapping, and check the Map object names automatically checkbox.
  3. Launch the Notepad application.

How to do it...

In order to create a test for multilingual application, we need to perform the following actions:

  1. Begin recording in TestComplete, and execute the following actions in the Notepad.
  2. Input some text into the text field.
  3. Then press Ctrl + Home.
  4. Opt for the Edit | Find... menu item.
  5. In the Find what field, get the word text inputted.
  6. Click on the Find Next button.
  7. And then click on the Cancel button.
  8. Stop recording by clicking on the Stop button in the Recording panel.
  9. In the result, the following script will be recorded:
    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();
    }
  10. Click twice on the NameMapping project element.
  11. In the right-hand side window part, click on the Mapped Objects heading to open it up.
  12. From the Configurations drop-down menu on the right-hand side part of the panel, select the Configuration Manager... element.
    How to do it...

    You will have Configuration Manager window opened with one configuration (Default Configuration).

  13. Click on the Copy As New button, and in the opened Add New Configuration window, type in a new configuration title (in our case, the name of the configuration may overlap with the language that's up for testing, for example, Russian, Danish, and so on).
  14. Click on the OK button in the Add New Configuration window.
  15. Close the Configuration Manager window.
  16. Now, in the Configurations drop-down list on the right-hand side panel, the newly created configuration is active (if that's not so, please select it from the Configurations drop-down list).
  17. Expand the Sys | Notepad elements in the Mapped Objects panel, and select the dlgFind element.
  18. In the right-hand side part, change the WndCaption property in such a way that it tallies up with the heading of the Find window for the selected language.
  19. Click on the button with the ellipsis to the right of the property value and in the opened Edit the WndCaption Property Value window, change the value of the Value field, and then click on the OK button. An example of the Russian configuration is shown in the following screenshot:
    How to do it...
  20. In the same way, change the properties for all the controls elements, in which the text is to be changed at the point of changing the application language (in our case, these are btnCancel and btnFindNext).
  21. Now, if we launch the previously recorded script, we will see this error in the log: The control item 'Edit' not found. That has happened because we have changed the headings for all the controls elements that are available in the NameMapping element; however, the names of the menu items have been written directly in the code, and they were not possible to transpose to NameMapping. The simplest way to resolve this problem is to create two objects that will contain the names of the menu items in different languages:
    var menuEng = {
      Edit: "Edit",
      EditFind: "Edit|Find..."
    };
    var menuRus = {
      Edit: "Правка",
      EditFind: "Правка|Найти..."
    };
  22. We will place these two objects outside our function and the function should be then modified in the following manner:
    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();
    }

How it works...

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.

There's more...

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";

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.172.132