This topic explains how to diagnose and resolve the “The window is invisible and thus cannot be activated” error that occurs during the test run. The topic contains the following sections:
Before simulating a click or other action on a control, TestComplete first tries to activate it. If it is impossible, it posts this error message to the log. The message indicates that something has changed in the tested application and that its state differs from the state it had during test recording. This topic explains how you can diagnose and fix this problem.
1. Explore the test log
-
Find the first error message in the test log. Depending on the command being executed, TestComplete may post several error messages to the log. This happens due to certain specifics of the test and script engines functioning (the script engine is used even when you run keyword tests, not scripts). Typically, the first error message corresponds to the problematic command and further errors are caused by this first error. Also, make sure that there is no ambiguous identification warning message.
The instructions in this topic assume that the first error message is the “The window is invisible and thus cannot be activated” error.
-
To better understand what test command was executed when the error occurred, double-click the error message in the test log. TestComplete will open your test for editing and automatically highlight the line that was executing when the error occurred.
2. Explore properties
Explore the properties of the desired objects, find the cause of the problem and fix it.
-
The tested application must be running and have the same state it had when the error occurred. If the application was closed after the test run, you can start it again and pause the run on the problematic test line. To do this:
-
Set a breakpoint on the problematic line in the script test or keyword test operation. To find that line or operation quickly, double-click the error message in the test log. TestComplete will switch to the test editor and highlight the line or operation that caused the error. To set the breakpoint, click the editor’s gutter next to the line or operation, or press F9.
-
Run your test. The test engine will automatically pause the test run when it reaches the breakpoint.
-
Look at your application and check whether the desired object exists. For instance, developers could change the tested application and remove the tested form or button from it. This change could cause an error in your test.
If the object does not exist in the application, re-record your test or update its commands to match the tested application.
If the object exists, then, to find the cause of the error, explore properties of the problematic object:
-
In TestComplete, select Display Object Spy from the Tools toolbar. This will open the Object Spy.
-
Use the Object Spy to select the needed object on the screen:
-
You typically select a window or control by dragging the target icon () to it. See how it works.
-
If you need to select a hint, menu item or another popup object, use the “Point and fix” mode. See how it works.
After you select the object, Object Spy will display its properties.
Below are typical causes of the problem and typical ways to eliminate them.
The tested object is invisible.
The tested object is invisible.The tested object is invisible.When TestComplete tries to perform an action with an object that is invisible on screen, it tries to activate it. If it is impossible to do that, it fails and posts an error message. To solve the problem, make sure that the Visible
property is set to True
when performing an action.
The object’s identification properties are not valid.
The object’s identification properties are not valid.The object’s identification properties are not valid.Description of a cause
To recognize windows and controls, TestComplete uses a number of properties that identify the object among its siblings. If the values of identification properties are no longer valid, or they do not provide unique recognition, TestComplete may select a wrong object that matches the current values of identification properties. In this case, all the actions that must be performed over the object, will be performed over the wrong object, which may cause an error.
Revising the identification properties
To determine the identification property values, select the MappedName
property of the object in the Object Browser panel and click the button. This will display the Name Mapping Item Information dialog box in which you view the mapping settings.
If the properties do not match the expected values or do not provide unique identification of the window or control, you need to change the mapping settings criteria. To do this:
-
Switch to the Project Explorer panel (you can do this by selecting View | Project Explorer from the TestComplete main menu).
-
In the Project Explorer, double-click the NameMapping item. This will invoke the Name Mapping Editor.
-
In the editor, expand the Mapped Objects section (by default, it is collapsed) and find the desired object in this section.
-
Select the object in the Mapped Object tree. The list of mapping settings that are used for this object will be shown on the right. You can modify the settings directly in list.
If you need to add more properties to the mapping settings, then you have to re-map the object. For detailed information on this, see Mapping Application Objects.
Before mapping the object, you may need to remove the existing mapping item and alias. To keep your tests working, you can assign the same alias to the newly mapped object. See Name Mapping - Aliases.
Some tips
-
If the identification criterion includes the Index
property and the value of this property has changed, then do not use this property for mapping as it does not provide the unique identification of the tested object in your case. Explore other properties of the missed object and try to find those properties that can be used to identify the object uniquely.
Note that besides using the object’s properties for identification, you can also use properties of its child objects. For instance, you can map a form by the text of one of its buttons or text boxes.
-
We recommend that you add the Visible = True
and/or VisibleOnScreen = True
properties for window or control identification. This may help you avoid the problem if it occurs due to the above-mentioned reasons.
-
Do not use the Name
and FullName
properties for object identification.
-
You can use wildcards (*
and ?
) or regular expressions to specify variable parts of the string property values. ?
stands for any single character, *
- for an arbitrary string. For instance, if the window caption looks like MyFile - Notepad, you can replace the file name with *
and use the following identification criteria: * - Notepad. To specify more complicated parts of a caption, use regular expressions.
You can use these wildcards to specify the value of any properties of the string type like WndClass
or wText
.
-
If you test an Open Applications: Open Applications provide the test engine with access to their internal objects, methods and properties. To map objects of these applications, TestComplete uses the object names defined in the application sources, for instance, edit11
, button1
and so on. If this name has been changed, you have to alter the mapping settings and use the new application-defined name for your tested object.
Incorrect identification properties of the object’s parents
If the object’s identification properties are valid, but this error message still arises, another possible reason is that values of identification properties of the object’s parents are no longer valid. For more information, please see the description of how to solve problems with the object’s identification properties above.
If it is impossible to set valid identification properties of the object’s parents, we recommend moving the desired object to the highest level of the mapped object hierarchy that it may occupy and command the test engine to search for the object from this level and deeper. To do this:
-
Open NameMapping project item in the Project Explorer panel to open the Name Mapping editor.
-
Find the desired object in the mapped object hierarchy, and drag the object to the highest level it may occupy.
-
Select the Extended Find check box for the object. This will command the test engine to search for the object starting from this level and deeper.
Note: |
The Extended Find column are hidden by default. To make it visible, right-click somewhere within the Mapped Objects panel and select Field Chooser from the context menu. This will display a list of available columns. Drag the Extended Find column from this list to the panel. |
To learn more about the Extended Find feature, see Using Extended Search Criteria in Name Mapping Repository.