An object map is a test asset that contains items that associate a logical name (an alias) with a control or a window, rather than the control or window's locator. Once a control is registered in an object map asset, all references to it in scripts are made by its alias, rather than by its actual locator name.
You can use object maps to store objects that you are using often in multiple scripts. Multiple tests can reference a single object map item definition, which enables you to update that object map definition once and have Silk4NET update it in all tests that reference the object map definition.
In your scripts, you can mix object map identifiers and locators. This feature enables you to keep your object maps relatively small and easier to manage. You can simply store the commonly used objects in your object maps, and use locators to reference objects that are rarely used.
The following construct shows a definition for a BrowserWindow where the locator is used:
_desktop.BrowserApplication("cnn_com").BrowserWindow("//BrowserWindow[1]")
The name of the object map asset is cnn_com. The locator that can be substituted by an alias in the object map is the following:
"//BrowserWindow[1]"
The object map entry for the BrowserWindow is BrowserWindow.
The resulting definition of the BrowserWindow in the script is the following:
_desktop.BrowserApplication("cnn_com").BrowserWindow("BrowserWindow")
If the index in the locator changes, you can just change the alias in the object map, instead of having to change every appearance of the locator in your test script. Silk4NET will update all tests that reference the object map definition.
// VB Window window = _desktop.Window("MyApplication") // object map id - the application window is used often MenuItem aboutMenuItem = _desktop.MenuItem("@caption='About'") // locator - the About dialog is only used once aboutMenuItem.Select()
// C# Window window = _desktop.Window("MyApplication"); // object map id - the application window is used often MenuItem aboutMenuItem = _desktop.MenuItem("@caption='About'"); // locator - the About dialog is only used once- aboutMenuItem.Select();