Turn your manual testers into automation experts!Request a Demo

Qt Testing: How to Test Qt Quick Controls Apps on Windows with testRigor

Weekly Newsletter
Receive weekly testRigor newsletters packed with insights on test automation, codeless testing, and the latest advancements in AI.

Qt is a popular framework for building desktop applications. With Qt Quick Controls, the app draws its own buttons, checkboxes and dropdowns instead of using the ones Windows provides. That is great for a consistent look, but it has often made these apps hard for test tools to read: a button looks like a label, and a dropdown looks like a plain text box.

testRigor can test Qt Quick Controls apps on Windows using plain-English steps. In this article we set up a suite and then go through a demo app screen by screen, showing the steps that work for each control.

What Should Qt Testing Cover?

A Qt app is usually a set of screens built from the same few controls, so covering each control type once tells you a lot. Start with the controls your users touch most:
  • Buttons and tab buttons
  • Checkboxes, radio buttons and switches, including their checked state
  • Dropdowns (combo boxes)
  • Text fields
  • Lists
  • Menus and toolbars
  • Dialogs and busy indicators

The demo app we use has one tab for each group. You can write one test per tab or run all of them in a single test, whichever suits your suite.

Qt Testing with testRigor: How to Perform End-to-End Tests

Run tests against a copy of the app that is safe to click through. Tests that save or delete data should use a test account or a test database.

Step 1: Log in to your testRigor account.

Step 2: Create a new test suite and configure it:

  • Enter a Test Suite Name, for example “Qt app”.
  • Set Type of testing to Native Desktop.
  • Under Where to run the tests, choose Use testRigor infrastructure to run tests on provided application, and set OS to Windows.
  • Set Number of test cases to generate using AI to 0 if you want to write the first test yourself.
  • Under Upload file, choose your app. testRigor supports .exe and .msi files (built for x86 or x86_64) and .zip files. The app is placed on the test machine’s desktop. What happens after the upload depends on the file type, which Step 4 explains.
Qt testing suite setup in testRigor

Step 3: Click Upload and Create to create the suite. Qt controls are recognized by default, so there is nothing to switch on.

Step 4: Create a reusable rule that opens the app. testRigor does not launch a Windows app for you in every case, and every test has to start with the app on screen, so put those steps in a rule once and call it from each test. You create rules under Reusable Rules in the suite menu.

What the rule has to do depends on what you uploaded:
  • A single .exe is placed on the desktop and started once, when the test machine is prepared, not before each test. If a test closes the app, the next test has to start it again, so the rule still needs to launch it after closing any old window.
  • A .zip is only unpacked on the desktop. The rule has to open the unpacked folder and start the app itself. The sample below assumes this case: a zip that unpacks to a folder named qt_app containing qtcontrolstest.exe.
  • An .msi runs an installer. The rule then has to open the installed app, and how that looks depends on your installer, so check it on your own setup.
The demo uses two rules. The first, cleanup previous test, closes anything left over from the previous test. It closes two windows: the app, and the File Explorer folder the previous run opened it from. If the folder window stays open, closing the app can return focus to it, and the next run will not find qt_app on the desktop.
if page contains "Qt Controls Test" then
  click "Qt Controls Test"
  press alt+f4
  wait 3 seconds
end

if page contains "Search qt_app" then
  click "Search qt_app"
  press alt+f4
  wait 3 seconds
end
The second, Open qt-control app, calls the first and then opens the unpacked folder, finds the executable and starts it. Each test begins with that one line.
cleanup previous test

click "qt_app"
press enter

click "qml"
press end
click "qtcontrolstest"
press enter

The screenshot shows this rule in testRigor. In your own rule, add a wait and a check at the end for something that only exists once the app has really started, for example wait 5 seconds up to 20 times until page contains "Current tab: Tab One", so a launch error does not look like a pass.

Qt testing: reusable rule that opens the Qt app

Step 5: Open the suite and, on the Test Cases page, click Add Test Case.

Qt testing suite dashboard in testRigor
Create a new Qt test case from the suite dashboard
Step 6: Enter a Description and the steps under Custom steps new line separated, then click Add and Run. The first test is just the rule, which proves the app opens:
Open qt-control app

How testRigor Finds a Qt Control

Three things are separate in a Qt app, and it helps to keep them apart when you write steps:
  • The visible text on screen, such as the label “Preferred choice” or “Entered text: My new value”.
  • The control’s accessible name and role, which Qt exposes to the operating system. In the demo app, the text field on the Inputs tab has no visible label, but it has the accessible name “Nickname”, and its role tells testRigor it is an input.
  • The control’s value, such as “My new value” typed into that field.

testRigor finds a control the way a person would, by the text on it or next to it, and it uses the accessible name and role to tell a field from a label that has the same text. That is why click input "Nickname" finds the field, and why check page contains "My new value" checks something different from the field’s value. The roles shown in this article, for example for list items and menu entries, are what the demo app exposes. Custom QML controls can expose different roles, so check what your own app reports. See Making your Qt app easier to test if a control has no name.

Setting Up a Safe Environment for Qt Testing

A few things make Windows desktop tests more stable:
  • Start every test from a clean desktop. A window left open by the previous test can steal the next test’s clicks. Close it at the start of each test, as the rule in Step 4 does.
  • Use a build made for testing. Point the suite at a test build with test data, not at production.
  • Expect name clashes with other windows. File Explorer has its own File, Copy and Paste. Use relative locators such as to the left of or above when a plain click is ambiguous.

Test Case: Exercise the Controls of a Qt App

The demo app has six tabs. You can put the steps for all of them in one test, or give each tab its own test. Either way, a test opens the app with the rule from Step 4:
Open qt-control app

To move to another tab, click its name, for example click "Inputs". The steps for each tab below assume that tab is already open, so add the tab click before them. In one combined test, add it between the blocks. In separate tests, add it after the rule. The steps use the demo app’s control names, so replace them with the names in your app.

Tab One: Buttons, Checkboxes and Radio Buttons

Qt testing: Tab One of the demo app with a button, a checkbox and radio buttons

For this screen, the following tests are possible.

Button. In the demo app, a button’s accessible name matches its visible text, so a plain click finds it. If a button looks right on screen but your locator misses it, check the accessible name. When the same word appears more than once, say that you mean a button.
check page contains "Button was clicked 0 times"

click "Push Button"
check page contains "Button was clicked 1 times"

To make clear that you mean the button, write click button "Push Button".

Checkbox. State checks read the real checked state of the control, so is checked and is not checked match what you see on screen.
enter "1" into checkbox "Check Box"
check that checkbox "Check Box" is checked

enter "0" into checkbox "Check Box"
check that checkbox "Check Box" is not checked
Radio buttons. Selecting one clears the others in its group.
check that radiobutton "Radio One" is checked
check that radiobutton "Radio Two" is not checked

click "Radio Two"
check that radiobutton "Radio One" is not checked
check that radiobutton "Radio Two" is checked

click radiobutton "Radio One"
check that radiobutton "Radio One" is checked

Inputs Tab: Dropdown, Text Field and Switch

Qt testing: Inputs tab of the demo app with a dropdown, a text field and a switch

For this screen, the following tests are possible.

Dropdown. select opens the dropdown and clicks the option, so it works with Qt’s popup list. You can also open the box yourself and click the item.
select "Option A" from "Preferred choice"
check that page contains "Selected option: Option A"

click "Option A"
click "Option B" below "Option A"
check that page contains "Selected option: Option B"

If the option cannot be found in the popup, the step fails. It does not fall back to typing the text, because typing into a drawn Qt popup can select the wrong item.

Text field. To add to what is already in the field, click it first and move the caret to the end. The assertions read the label that mirrors the field’s value (“Entered text: …”), so they prove what the field holds, including the appended text. A bare check page contains "typed 123" could match any other text on the screen.
enter "My new value" into "Nickname"
check that page contains "Entered text: My new value"

click input "Nickname"
press end
type " typed 123"
check that page contains "Entered text: My new value typed 123"

Use click input "Nickname" rather than click "Nickname" when the same text could also match a label.

Switch.
click "Switch"
check that page contains "Switch is: on"

Lists Tab

Qt testing: Lists tab of the demo app
For this screen, the following tests are possible. In the demo app, list items can be clicked by their text, or addressed as buttons when the text also appears elsewhere.
check page contains "No list item selected"

click "List Item 2"
check page contains "Selected list item: List Item 2"

click button "List Item 4"
check page contains "Selected list item: List Item 4"

Menus Tab: Menu Bar and Toolbar

Qt testing: Menus tab of the demo app with a menu bar and a toolbar
For this screen, the following tests are possible. In the demo app, menu bar entries such as File and Edit are not exposed as buttons, so click them by their text. Use a position relative to a neighbor when the same word also appears in another window, for example File Explorer’s own File menu or Copy button. Entries inside a menu popup and toolbar buttons can be clicked as buttons.
check page contains "No menu/toolbar action yet"

click "File" to the left of "Edit"
click "Open"
check page contains "Last action: Open"

click "File" to the left of "Edit"
click button "Save"
check page contains "Last action: Save"

click "Edit" to the right of "File"
click "Copy" above "Paste"
check page contains "Last action: Copy"

click button "Cut"
check page contains "Last action: Cut (toolbar)"

click "Copy" to the right of "Cut"
check page contains "Last action: Copy (toolbar)"

The last two actions use different locators because of the names. “Cut” appears only once on the screen, so click button "Cut" is enough. The Edit menu entry and the toolbar button share the name “Copy”, so each step names the control by its neighbor. above "Paste" identifies the Edit menu’s Copy, and to the right of "Cut" identifies the toolbar’s Copy.

Indicators Tab: Busy Indicator

Qt testing: Indicators tab of the demo app with a spin box and spinner buttons
For this screen, the following tests are possible. A spinner has no value to read, but it can have an accessible name that exists only while it is visible. The demo has buttons that start and stop it, so it stays visible long enough to observe. The spin box has a value, but testRigor cannot read it directly (see Current limits), so the demo shows it in a label that you can check.
check page contains "Spin box value: 10"
check page does not contain "Loading spinner"

click "Start spinner"
check page contains "Loading spinner"

click "Stop spinner"
check page does not contain "Loading spinner"

In your own app, a spinner usually disappears when an operation finishes. Then test the result of that operation with a bounded wait, such as wait 2 seconds up to 30 times until page contains "Import complete", instead of trying to catch a short “Loading” state.

Dialog Tab

Qt testing: Dialog tab of the demo app
For this screen, the following tests are possible. The dialog’s text and buttons can be checked and clicked like anything else on the screen.
check page contains "Dialog not yet closed"

click "Open Dialog"
check page contains "This is a dialog."

click "OK"
check page contains "Dialog result: OK"

click "Open Dialog"
check page contains "This is a dialog."

click "Cancel"
check page contains "Dialog result: Cancel"

Making Your Qt App Easier to Test

A few choices in the app make steps shorter and more reliable:
  • Give controls a unique accessible name (Accessible.name in QML). Steps find controls by name, so a control with no name, or a name that repeats on screen, is hard to target.
  • Avoid a visible label that repeats the text of the control it sits next to. A step may click the label instead of the control.
  • Mirror typed text in a label. Text typed into a text field is not exposed as the field’s name. Show it in a label and assert on that label.

Current Limits

Qt can expose a value for sliders, spin boxes and dials, and progress bars are read-only. testRigor does not currently have steps to read or set the value of these controls, so in the demo setup their value cannot be asserted or changed directly. Assert on a label that mirrors the value, or use a button that changes it.

Conclusion

Qt Quick Controls apps can be tested with the same plain-English steps as any other app: click a button, enter text, select from a dropdown, check a state. Create a Native Desktop suite, open the app with a reusable rule, name your controls well, and start with the paths your users take most, such as submitting a form, changing a setting and confirming a dialog.

You're 15 Minutes Away From Automated Test Maintenance and Fewer Bugs in Production
Simply fill out your information and create your first test suite in seconds, with AI to help you do it easily and quickly.
Achieve More Than 90% Test Automation
Step by Step Walkthroughs and Help
14 Day Free Trial, Cancel Anytime
“We spent so much time on maintenance when using Selenium, and we spend nearly zero time with maintenance using testRigor.”
Keith Powe VP Of Engineering - IDT
Related Articles

How to Use Built-in Reusable Rules in testRigor

testRigor provides several built-in reusable rules for common actions such as logging in, signing up, logging out, and selecting ...

How to Test Passkey Logins with testRigor

How to test login to Salesforce testRigor can now log in with a passkey, so tests are no longer blocked when a site asks for one. ...
Privacy Overview
This site utilizes cookies to enhance your browsing experience. Among these, essential cookies are stored on your browser as they are necessary for ...
Read more
Strictly Necessary CookiesAlways Enabled
Essential cookies are crucial for the proper functioning and security of the website.
Non-NecessaryEnabled
Cookies that are not essential for the website's functionality but are employed to gather additional data. You can choose to opt out by using this toggle switch. These cookies gather data for analytics and performance tracking purposes.