Recognizing Tested Objects on Localized Versions of Operating Systems

Applies to TestComplete 14.40, last modified on April 22, 2021
Information in this topic applies to desktop and web applications.

Task Description

Parameters used for object naming in your application under test can be different depending on the running operating system. For example, if you run your tests on several localized versions of the operating system, the text of the control captions used for control naming will be different.

Make sure that parameters you use to obtain desired objects in tests take into account differences between localized operating system versions.

Possible Solutions

  • Name Mapping - If the object hierarchy in your tested application is the same for all of your target operating systems, you can use the same name map with several name mapping configurations for object identification and refer to tested objects by their mapped names rather than by default names. The name mapping configuration will store object recognition parameters specific to each target operating system.

    In order to apply the desired name mapping configuration from test, you can use the NameMapping.CurrentConfigurationName property.

    JavaScript, JScript

    function Test()
    {

      // Obtains the system locale
      var locale = aqEnvironment.LanguageForNonUnicodePrograms;

      // Applies the corresponding Name Mapping configuration
      switch (locale)
      {
        case "English (United States)":
          NameMapping.CurrentConfigurationName = "ConfgEn";
          break;
        case "Bulgarian (Bulgaria)":
          NameMapping.CurrentConfigurationName = "ConfgBg";
          break;
        case "French (Belgium)":
          NameMapping.CurrentConfigurationName = "ConfgFr";
          break;
        …
        default:
          NameMapping.CurrentConfigurationName = "ConfgDefault";
      }

      // Performs the testing
      …
    }

    Python

    def Test():
    
      # Obtains the system locale
      locale = aqEnvironment.LanguageForNonUnicodePrograms
    
      # Applies the corresponding Name Mapping configuration
      if locale == "English (United States)":
        NameMapping.CurrentConfigurationName = "ConfgEn"
      elif locale == "Bulgarian (Bulgaria)":
        NameMapping.CurrentConfigurationName = "ConfgBg"
      elif locale == "French (Belgium)":
        NameMapping.CurrentConfigurationName = "ConfgFr"
        ...
      else:
        NameMapping.CurrentConfigurationName = "ConfgDefault";
      
    
      # Performs the testing
      ...

    VBScript

    Sub Test

      ' Obtains the system locale
      locale = aqEnvironment.LanguageForNonUnicodePrograms

      ' Applies the corresponding Name Mapping configuration
      Select Case locale
        Case "English (United States)"
          NameMapping.CurrentConfigurationName = "ConfgEn"
        Case "Bulgarian (Bulgaria)"
          NameMapping.CurrentConfigurationName = "ConfgBg"
        Case "French (Belgium)"
          NameMapping.CurrentConfigurationName = "ConfgFr"
        …
        Case Else
          NameMapping.CurrentConfigurationName = "ConfgDefault"
      End Select

      ' Performs the testing
      …

      End Sub

    DelphiScript

    procedure Test();
    var locale;
    begin

      // Obtains the system locale
      locale := aqEnvironment.LanguageForNonUnicodePrograms;

      // Applies the corresponding Name Mapping configuration
      case locale of
        'English (United States)':
          NameMapping.CurrentConfigurationName := 'ConfgEn';
        'Bulgarian (Bulgaria)':
          NameMapping.CurrentConfigurationName := 'ConfgBg';
        'French (Belgium)':
          NameMapping.CurrentConfigurationName := 'ConfgFr';
        …
        else
          NameMapping.CurrentConfigurationName := 'ConfgDefault';
      end;

      // Performs the testing
      …

    end;

    C++Script, C#Script

    function Test()
    {

      // Obtains the system locale
      var locale = aqEnvironment["LanguageForNonUnicodePrograms"];

      // Applies the corresponding Name Mapping configuration
      switch (locale)
      {
        case "English (United States)":
          NameMapping["CurrentConfigurationName"] = "ConfgEn";
          break;
        case "Bulgarian (Bulgaria)":
          NameMapping["CurrentConfigurationName"] = "ConfgBg";
          break;
        case "French (Belgium)":
          NameMapping["CurrentConfigurationName"] = "ConfgFr";
          break;
        …
        default:
          NameMapping["CurrentConfigurationName"] = "ConfgDefault";
      }

      // Performs the testing
      …
    }
  • Regular expressions - TestComplete allows you to use regular expressions in object captions when calling methods that simulate user actions (ClickItem, SelectItem, CheckItem, ClickCell, and so forth). When the control's caption can have several variants in different languages, you may use regular expressions to list all possible variants of the caption.

    The following code shows how to identify a grid cell using the column's caption in English, German, French, and Spanish locales:

    JavaScript, JScript

    function LocaleIndependentDemo()
    {
      var dataGridView;
      var dataGridViewTextBoxEditingControl;
      var caption;
      TestedApps.DataGridViewSample.Run();
      dataGridView = Sys.Process("DataGridViewSample").WinFormsObject("Form1").WinFormsObject("dataGridView1");
      // Set a regular expression pattern that specifies a caption in multiple languages
      caption = /(Customer Name)|(Kundenname)|(Nom du client)|(Nombre del cliente)/
      dataGridView.ClickCell(3, caption);
    }

    Python

    import re
    def LocaleIndependentDemo():
      TestedApps.DataGridViewSample.Run()
      dataGridView = Sys.Process("DataGridViewSample").WinFormsObject("Form1").WinFormsObject("dataGridView1")
      # Set regular expression pattern that specifies caption in multiple languages 
      caption = re.compile("(Customer Name)|(Kundenname)|(Nom du client)|(Nombre del cliente)")
      dataGridView.ClickCell(3, caption)

    VBScript

    Sub LocaleIndependentDemo
      Dim form1
      Dim dataGridView
      Dim caption
      TestedApps.DataGridViewSample.Run
      Set form1 = Sys.Process("DataGridViewSample").WinFormsObject("Form1")
      Set dataGridView = form1.WinFormsObject("dataGridView1")
      ' Create a regular expression
      Set caption = New RegExp
      ' Set a regular expression pattern that specifies a caption in multiple languages
      caption.Pattern = "(Customer Name)|(Kundenname)|(Nom du client)|(Nombre del cliente)"
      Call dataGridView.ClickCell(3, caption)
    End Sub

    DelphiScript

    procedure LocaleIndependentDemo;
      var dataGridView : OleVariant;
      var caption : OleVariant;
    begin
      TestedApps.DataGridViewSample.Run;
      dataGridView := Sys.Process('DataGridViewSample').WinFormsObject('Form1').WinFormsObject('dataGridView1');
      // Create a regular expression
      caption:=HISUtils.RegExpr;
      // Set a regular expression pattern that specifies a caption in multiple languages
      caption.Expression := '(Customer Name)|(Kundenname)|(Nom du client)|(Nombre del cliente)';
      dataGridView.ClickCell(3, caption);
    end;

    C++Script, C#Script

    function LocaleIndependentDemo()
    {
      var dataGridView;
      var dataGridViewTextBoxEditingControl;
      var caption;
      TestedApps["DataGridViewSample"]["Run"]();
      dataGridView = Sys["Process"]("DataGridViewSample")["WinFormsObject"]("Form1")["WinFormsObject"]("dataGridView1");
      // Set a regular expression pattern that specifies a caption in multiple languages
      caption = /(Customer Name)|(Kundenname)|(Nom du client)|(Nombre del cliente)/
      dataGridView["ClickCell"](3, caption);
    }

  • Parametrization - You can use external files to store recognition parameters specific to each target operating system and retrieve them during the test run to use for object recognition.

See Also

aqEnvironment Object
About Name Mapping
Using Regular Expressions in Scripts

Highlight search results