Hi Joachim,
You can map objects by language-independent properties (see the "Name Mapping" help topic for more information). For example, in MFC applications, you can use the ControlID property. Values of this property correspond to the objects' IDs defined in the resource.h file of an MFC application.
Objects in .NET applications are recognized in TestComplete scripts by their native names, so it will be easier to create a localized script for a .NET application. Most likely, you will just need to change names of menu items, list box items, etc.
To make your scripts language-independent, you can either create several Name Mapping configurations (one per each localized version of the application) or use the following approach:
1. Record your test script with a "baseline" version of your application (for example, the English version).
2. Create an Excel file with localized names. For example:
EnText1 EnText2 EnText3 ...
FrText1 FrText2 FrText3 ...
DeText1 DeText2 DeText3 ...
... ... ...
3. In TestComplete, add the following lines at the beginning of your main script (outside any function):
[JScript]
var d = Sys.OleObject("Scripting.Dictionary");
d.RemoveAll();
This code will create a global Dictionary object which will store all localized window captions. Baseline captions will be used as keys. If your project contains several script units, you will need to use this object in all of them. Please see the "Calling Routines and Variables Declared in Another Unit" help topic to learn how to use objects declared in different units.
4. Replace all WndCaption values in your scripts with appropriate values from the Dictionary object. For example, the following line:
p.Window("MyWndClass", "My English window caption");
should be replaced with:
p.Window("MyWndClass", d.Item("My English window caption"));
You can use the "Replace All" ("Edit | Find and Replace | Replace All") functionality to replace all strings automatically.
5. Add a function that will read the localized captions from the Excel file to your main script. You can pass the required language as a parameter. Please see the "Using DDT Drivers" help topic to learn how to retrieve data from external storages (for example, Excel files) in TestComplete.
To add a value to the Dictionary object, use the Dictionary.Add method. For example:
d.Add("My English window caption", "My localized window caption");
Please see the following MSDN Library article for more information on the Dictionary.Add method:
http://msdn2.microsoft.com/en-us/library/5h92h863.aspxYou can use the following sample script to initialize a global dictionary object with values read from an Excel file:
[JScript]
// MultilanguageSupport Unit
var d;
function InitializeDictionary(languageName)
{
d = Sys.OleObject("Scripting.Dictionary");
d.RemoveAll();
var ddtDriver = DDT.ExcelDriver(Project.Path + "LanguageMapping.xls", "Sheet1", true);
var languageColumnIndex = 0;
for(languageColumnIndex = 0; languageColumnIndex < ddtDriver.ColumnCount; languageColumnIndex++) {
if (languageName == ddtDriver.ColumnName(languageColumnIndex))
break;
}
if (languageColumnIndex >= ddtDriver.ColumnCount) {
Log.Error("The " + languageName + " language was not found");
return false;
}
while(!ddtDriver.EOF()) {
d.Add(ddtDriver.Value(0), ddtDriver.Value(languageColumnIndex));
ddtDriver.Next();
}
}
// Main Unit
//USEUNIT MultilanguageSupport
function Main()
{
InitializeDictionary("English");
//.....
}
A sample Excel file is attached. Please note that the file must be located in your TestComplete project folder so the script can work correctly. If you want to save the file to another location, you will need to change the file path in the following line:
var ddtDriver = DDT.ExcelDriver(Project.Path + "LanguageMapping.xls", "Sheet1", true);