Squish Qt tips & tricks: Working with objects without unique properties
At Spyrosoft, we know that when it comes to software testing, efficiency and precision are crucial. This is where Squish, a versatile framework for automated GUI testing, comes in. In this article, we share tips and tricks for some of the most common problems in Squish when working on Qt test automation projects and delve into working with objects that don’t possess properties on which software testers can typically rely.
What are Qt applications?
Qt apps are developed using the Qt framework. Qt is a cross-platform, C++-based framework that provides a wide range of tools and libraries for developing GUIs (graphical user interfaces) and other software components for desktop, mobile and web applications.
The biggest advantage of Qt apps is that they can run on multiple operating systems, including Windows, macOS, Linux, Android, iOS, etc. With Qt apps, developers can write code once and deploy it on various platforms with no need to deal with significant code modifications.
Because of this versatility, Qt is commonly used in various industries, especially when it comes to creating cross-platform applications with rich graphical interfaces.
Learn more about Qt services.
What is Squish?
In brief, Squish is an automated testing tool primarily designed for testing graphical user interfaces (aforementioned GUIs) in applications developed with Qt. Squish is one of our main testing tools, mainly because of the significant benefits this tool offers:
- Cross-platform capabilities: Squish supports a wide range of platforms, including Windows, macOS, Linux/Unix, iOS, Android, and various embedded systems. As a result, we can use the same testing processes across different platforms.
- Support for diverse GUI Technologies: We use Squish to test applications built using various GUI technologies, such as Qt, Java, Windows Forms, Web (HTML5/JavaScript), and more.
- Automated testing: Squish can be integrated into CI/CD processes, which makes automated testing possible and effective. This way, we can deal with potential issues early in the development process.
- Squish GUI Tester: The Squish GUI Tester is a versatile tool for executing automated tests across various scenarios, including distributed batch testing and hybrid applications. It supports multiple scripting languages and offers an intuitive environment for recording and playback, enhancing the testing process.
Want to learn more about our Qt services offer?
Go to pageSquish for Qt – handling QA automation obstacles
After this short introduction, it is time to talk about one of the most common obstacles while working on test automation: Missing the unique ID on the object we want to use for our automation script.
Producing stable and powerful test scripts is crucial in overcoming these QA automation obstacles. These scripts simplify test creation, maintenance, and troubleshooting, especially when leveraging object maps and object identification tools.
While working with Squish, we can use other properties of objects that are unique and can be leveraged for accurate and reliable automation. However, occasionally we miss both of these crucial ingredients for successful automation. For example, this can occur due to a lack of cooperation from developers or just because some of the specific QML properties that cause the side effect of having multiple elements with the same properties.
In this example, the QML developer attempts to create a list of buttons with some labels. Of course, this can be modified to create a unique ID, but test automation often starts late after project development begins, and there is a huge technical dept. The output of the above code looks like this:
Now, if we would like to start automating tests on such a UI, we should follow the received requirements, which tell us to interact with the button next to menu item 1. After opening Squish and using the selector on the switch next to menu item 1, we get this as a locator dictionary:
As we can see, there is a generic ID, which is the same for all switches on that menu. We can’t use this because the occurrence property causes instability in tests once something is added to that menu.
Working around graphical user interfaces tests in Squish for Qt
In the past, the Froglogic blog has posted code for traversing the QML tree to find children of your selected object and expected objects. The post itself was really helpful, but with little enhancement, it can be an excellent tool for working around such issues as in the example above. Here is the code for finding these children with the enhancement, for which we give an explanation below:
With the above functions, we can select any object that can be a sibling of the thing we are looking for, or even a great grandchild of a sibling of such an object. So, let us look at this, starting with the basics. Here is the QML tree displayed in Squish with you’re the desired object selected:
The binary tree of this looks like this:
Running the code below can get us an exact reference to our desired switch:
Now, let’s have a closer look at the whole process:
- We traverse up the QML tree to Row 0 with parent_container.parent and parent_count=1
- Next, we are creating our list to store the children we find.
- Finally, we loop over the children in the container, looking for the desired type or properties. We store all matching objects in a list, and then we use recursion to run deeper, looking for grandchildren, etc.
- We output results as a list (we used [0] because we were expecting a single child matching our desired requirements).
Having IDs or unique properties is always the best way of working. However, there are times when, whether due to technical debt or tight deadlines, we can’t get developers to add these missing things that are vital for our test automation scripts. While the above solution combining Squish with QT is not perfect, it still delivers tools to work around some of the issues and can be a great test automation enhancement if used carefully.
Summary
To sum up, both Qt and Squish are powerful tools for efficient software development and its testing. Qt is a versatile framework for cross-platform development, while Squish automates and enhances testing procedures. Putting these tools together streamlines development and ensures high-quality software by automating testing, naturally contributing to significant time and cost savings.
If you are looking for an experienced team that can help you develop a Qt application or test it using Squish, we are at your service. To learn more about Squish for Qt, check our Qt services or contact us directly via the form below.
About the author
RECOMMENDED ARTICLES
CONTACT US