Quantcast
Viewing all articles
Browse latest Browse all 68

Using Wildcards in TestComplete NameMapping

If your tested objects are named dynamically, you can use wildcards in TestComplete NameMapping to allow greater flexibility. For example, the main window in the sample C# Orders application that ships with TestComplete is named “MainForm”. Very nice, but what if  each time a window appears it is named “wnd012345689123″ or “wnd9999999″? Only the “wnd” portion of the name remains constant.

Lets look at a slightly tweaked version of the orders app that dynamically names the main window every time it loads. The Object Browser shows the new name.

Image may be NSFW.
Clik here to view.
Main form in the Object Browser

If you right-click the WinFormsObject and select Map Object from the context menu, and select the Map the object as choice, TestComplete will name the object automatically using default properties. The NameMapping window shows that TestComplete looks for a NativeClrObject.Name property that matches the dynamic name. The next time you test and the window is reopened, the window will have a new name and the test will fail.

To fix this, edit the NativeClrObject.Name property to use a wildcard, either a “*” to match any number of characters or “?” to match any single character.

Image may be NSFW.
Clik here to view.
Editing the NativeClrObject.Name property

That change will allow TestComplete to find any window that has a NativeClrObject.Name starting with “wnd” and following with any characters. You should also change the name in the Mapped Objects window to something sensible that you can remember later like “MainForm”.

Image may be NSFW.
Clik here to view.
The NameMapping using a wildcard.

To make sure this is working, you should run a bit of code like the example below that opens the window several times, accesses the window, and records that the name changes each time.

function TestDynamicNames()
{
  for (i=0; i < 3; i++){
    TestedApps.Orders.Run(); 
    Aliases.Orders.MainForm.Activate(); 
    Log.Message(Aliases.Orders.MainForm.NativeClrObject.Name);
    TestedApps.Orders.Close();  
  }
}

The log reflects that NameMapping using wildcards is finding the window each time, even though only part of the NativeClrObject.Name is the same each iteration.

Image may be NSFW.
Clik here to view.
The test log showing the name changes

The post Using Wildcards in TestComplete NameMapping appeared first on Falafel Software Blog.


Viewing all articles
Browse latest Browse all 68

Trending Articles