Codementor Events

Qt Automation 02: Control Spying

Published Nov 30, 2018
Qt Automation 02: Control Spying

In the previous post, which is Qt Automation 01: Jump Start with the First Sample, we have created a small Node.js script with to automated Qt application. In that example, the created automation script is composed of two parts: the model file and the JavaScript code. The model file is also called the object model file, which stores the test object information of the UI controls. The JavaScript code use these object and contains automation logics.

When doing Windows UI automation, the first step is to spy all needed controls and add them to object model. In this post we will talk specifically about how to spy Qt UI controls with Model Manager in CukeTest.

Before we introducing how to locate the UI control, let's take a brief look at the main functions provided by the Model Manager, which is a built in component of CukeTest. The following image is the object model created in the previous section.

01.png

On Model Manager UI, the left part is the object tree of the model, which lists the test object and their hierarchy. The right panel displays the details of a selected object, including identification properties, method and properties of this object, and also the screenshot of the control.

In the previous post, we introduced how to add objects with “Add Object” dialog. In addition to this, you can also add controls in batches and spy controls on the fly.

Add controls in bulk

Use the "Batch Add Controls" function to add objects for multiple controls at once.

picture2_toolbar.png

Take the Qt "Address Book" sample application as an example, it can be found in the demo samples shipped with Qt framework. There are multiple tabs on this application, if you want to add objects for all these tabs, it is recommended to use the [Batch Add Control] dialog.

picture3_addressbook.png

Below are the actions:

In the Model Manager, click the "Batch Add Controls" button, and select one of the above controls in the Address Book. For example, select a TabItem control, such as [ABC], and CukeTest will automatically recognize other controls that are on the same level as this control. As shown below:

picture4_batch_add.png

When you select any object in the list, the screenshot of the corresponding control is also displayed. You can add all these objects to the object model by checking the corresponding checkboxes.

picture5_controls_added.png

Control spying

Open the "Control Spying" pop-up detection panel, it can perform real-time detection.

Click the "Start Spy" button to spy the control: When your mouse is on a Windows control, it will have a red border around the control identified, and the spying dialog will display the detected control information, including the control properties that can be used to locate the control, and other properties.

Once the control concerned is shown, click mouse, and it will stop spying, then you click the "Add" button and add it to the object model.

picture6_spy.png

Complex element addition

In most occasions, click-to-select pattern works during control spying. However, it does not apply to menu items. When select a menu item, one need to first click to open the parent menu. There need a few clicks to finally select menu item you want to add. In this case, you can use “Ctrl” key in the previous few clicks, to indidate to the spyer that you want to continue control spying, so that spying can ignore the mouse click and continue until there is a click without “Ctrl” key.

In the Address Book application, when clicking menu [File]--[Open], you can can hold the “Ctrl” key when click [File] menu and release it when click [Open] menu.

picture7_ctrl.png

The specific practices are as follows:

  1. Open the Model Manager, click the "Add Object" button, and move the mouse to "File"

picture8.png

At this point, press the "Ctrl" button and hold it, click "File" menu and the menu pops up.

picture9.png

  1. Then release "Ctrl" key, moves mouse to "Open..." menu item and click it, hold the mouse for about a second till "Add Object" dialog appears, you should see that "Open" menu item is detected by the spyer and its properties are also shown.

picture10.png

To sum up

In Model Manager, you can add controls in 3 ways, which are “Add Object”, “Batch Add Controls” and “Spy”, while all of them can add controls to the model, they have some different behaviors. Use them appropriately can help boost the speed of your model creation. When encountering complex operations, you can perform the operations while holding "Ctrl" keys, until the control you want to spy is shown.

Discover and read more posts from CukeTest
get started