Qt QML Desktop application automation testing - c++

I have a task to automate Qt QML based desktop applications through open source frameworks. I am completely new to testing and also to Qt QML. I am good with Java and Python and also Javascript.
Can someone please suggest a way to write automation tests for Qt QML desktop application?
Can I code things to read the elements and widgets in the Qt QML applications?, So I can validate various cases.
If so, are there any tutorials or sample automation test projects for Qt QML applications?

Have a look at Spix. Once you link against it, you can remote control your QML UI by sending fake events, either from C++, or from a script using RPC. Any scripting language that supports XML-RPC, like python, can be used.
This way, you can automate and test your Qt/QML application.
Objects are identified by paths, so you don't have to deal with coordinates. Spix finds the item by the objectName property set in QML.
You can also query object properties from the script...
The library is fairly new and under development, but I think it already covers a lot of the more common use cases in desktop apps...

Related

Qt c++ application scraping

I would like to interact with an opened qt window (wrote in c++) using code. The code would act like a user and will be completely independent of the code of the qt window. Something like web scraping but with qt (which is much more complicated).The first thing I’m attempting to do is to mimic a click on a push button.
My first intuition was to add some c++ code to the existing code at runtime and execute something like « pushButton.click(); ». After some few searches I tried to use dynamic shared library. The library would implement the code of the button I want to click on, and would be dynamically added to the existing c++ code. This solution could work but seems to be very complicate and not portable. Furthermore I would like the solution to be very independent of the window code.
Of course the qt code of the window will be accessible from the scraping code side.
Are some other solutions more practical ?
EDIT:
GammaRay seems to work fine. I manage to perform a click on a pushButton using the GUI. However, GammaRay doesn't seem to provide a command line interface form. As we can read in the official documentation:
The GammaRay client is available in two forms:
as a standalone application as depicted in the following screenshot
as Qt Creator plugin (for Qt Automotive Suite only)
Is there any possibility to perform a click using GammaRay and without GUI? Are some other solutions work using code only?
The purpose of GammaRay is introspection and not automation. I recommend to use Squish (https://www.froglogic.com/de/squish/editions/qt-gui-test-automation/), depending on the required licenses the price is not so high.
If you don't want to spent the money, then you have to create your own IPC Interface with Remote Commands.

Adding Qt Widgets to MainWindow at Run Time

Here is my situation:
I'm developing a C++ application in Creator/Designer with Qt 5.6 on Windows 7 64-bit
I'm designing a skeleton GUI that doesn't do much on its own. It mainly provides a mechanism to integrate engineering tools built by other developers (Plug-ins if you will, not to be confused Plug-ins to Qt itself). The skeleton will be installed on workstations around the office, and it should be able to pull these Plug-ins from a network location and install them to the skeleton without recompiling. On startup, the skeleton should read its list of Plug-ins and build its menus, toolbars, and UI Widgets accordingly.
So the question is ultimately this: Does Qt provide a way of adding .ui files and associated code to a QMainWindow at run time?
Can it do so in such a way that the skeleton will not have to be changed, recompiled, and re-deployed whenever new Plug-ins are created?
Close, but no cigar: Here is an example of a calculator UI created in Designer being pulled into another program dynamically, but it appears this method uses the .ui file only. In other words, the boxes and buttons are pulled from the .ui file, but its logic is implemented in the "skeleton." I need to do something akin to embedding the calculator as its own fully functional Widget at run time.
Side question: If there isn't a nice mechanism provided by Qt, are there disadvantages to having the other developers compile their Plug-ins as DLLs for my particular case?
There's some basic misunderstanding of what a Qt application does. Every single widget you're seeing is instantiated by executing C++ code - it is all done dynamically, at runtime. The uic takes a foo.ui file and turns it into ui_foo.h. That defines a class that can populate a base widget with children.
You can use the QUiLoader to parse a .ui file and instantiate its objects at runtime, but there's little point to doing that since the other code is still C++, so it's simplest to have a plugin project that converts .ui files into C++, then compiles those along your other code and links them into a plugin dll.
The plugins are simply .dlls, ideally providing functionality consumable by the Qt plugin system, that have all the code needed: the code the comes from .ui files via uic, and the code the plugin authors wrote by hand. A plugin is an object factory: it will create QObject instance(s) that can then provide your skeleton with all the widgets and other objects it needs.
That's all. The plugins are .dlls, and you're of course free to download them from a network location to a cache folder, and open them at runtime.
There's no difference between plugins "to Qt itself" and plugins to your application: Qt is C++ code, just as your application is. While it can consume the functionality of some plugins, the rest of them are for your code to consume.
For inspiration, you should look at the sources of Qt Creator itself. It is a completely plugin-based application, the core is a plugin container that doesn't do much. Probably you could reuse the Qt Creator core as the basis for your application, with either no changes or very minimal changes. It would come with a network discovery plugin that gets the remaining plugins from the server and into the cache, and then loads them up. Such a plugin can be probably written in 150 lines of code, excluding the minimal boilerplate :)

Embedd an external application in a widget under Qt

I was wondering either it is possible to run an external application inside a QT widget under windows operating system. For example, if I were to write a Qt gui application, where in one of the dialogs user could write some text, I could use a textbox there or something similar. But instead, would it be possible to run Notepad++ or windows notepad application in that dialog?
I would appreciate all help.
It is not really practical to do what you describe at the application level, embedding an entire process into a window of another. (It would be technically difficult and the user experience would likely be pretty bad if you could pull it off.)
Fortunately, this very problem of application components has already been solved!
So it is possible to get the end result you describe via a slightly different mechanism. Many applications expose COM interfaces for automation and embedding, and it is possible to embed COM objects within a Qt application.
(Older technologies such as DDE, OLE and ActiveX provided various aspects of this but are all basically deprecated in favour of COM AFAIK.)
Hopefully you can find a COM object from a third party, or find an app that exposes its components via COM and assemble your app that way.
Have a look at the Qt documentation:
Active Qt - ActiveX and COM support for Qt

C++/Lua: Implement Qt/QtLua with QWebView

I'm planning to write a cross-platform project in C++, which will run a Lua engine. I'd like to write the main program for that project including the GUI in Lua. And to make it even easier, I want to write the GUI in HTML and therefore I need an additional library, hopefully QtLua which is based on Qt.
From what I heard, implementing QtLua into the Lua engine shouldn't be too hard and Qt has a nice class called QWebView that should allow me to write HTML GUIs. But I'm wondering about 2 things:
Is it cross-platform capable?
Is QWebView even part of QtLua?
Answers to both questions i think you should find here http://www.nongnu.org/libqtlua/
There's this part that says
QtLua is not designed to develop an application in pure Lua but rather to extend a Qt C++ application using Lua as scripting language.
Therefore, if your application is built/based on Qt and only extended using Lua, it should be cross-platform capable.
And for your second question; QWebView is used to view and edit web content, QtLua or QtScript is used to provide support for application scripting. QWebView is not part of QtLua plus i don't see any member of the QWebView class that has any connection with scripting

How to add custom class processing functionality in Qt

I'm a little new to Qt. I have been programming in C++ for quite a while.
I want to create an application in Qt/C++ just because it's very easy to create the GUIs. I wanted to know that is it possible that I can write a C++ class in native C++ and use it in my Qt application.
I want to write the GUI in Qt and do all processing using my native C++ code rather than Qt/C++. Is it possible to compile a DLL in native C++ and then load and use it in QtC++ application?
I really want to write a GUI application using C++.
There is no such thing as "native C++" as opposed to "Qt/C++", so the question makes little sense. All of core Qt code is compiled native C++, just as any C++ application that uses Qt is.
As JBentley has duly noted:
[You may be] confused because of the code generating tools Qt uses, like moc [or uic]. Those don't mean that C++ compiles natively while Qt doesn't. All those tools do is provide a convenient way to produce a lot of boiler code that the framework relies on, so that the programmer can pretend they don't exist and use things like Qt's slots and signals. The final code which you compile and link is ordinary C++, with calls into the Qt library (also C++) which you've used.
If what you're asking is "am I forced to use Qt classes in all parts of my application", then no - nobody's forcing you to do that. If you already have parts of your application written using boost, or standard C++ library classes, it's fine.
You have to understand that Qt has modular design and provides a lot of non-GUI functionality. You can use the non-gui modules in the non-gui part of your code. It's a fairly clean and general purpose application development framework. It's perfectly fine to use it for various internet server applications, for example.
The following Qt modules are of note for non-gui development:
Core: Core non-graphical classes: containers, event loop, timers, threads, state machines, internationalization, XML, json, file I/O - all of it portable.
Network: Classes to make network programming easier and more portable. Includes secure sockets, HTTP requests, etc.
SQL: Classes for database integration using SQL.
You are able to use any C++ code you would like. I have have actually had questions with the same thought process in my day to day work. First you need to grok the idea that Qt uses normal C++ and special tools to create a robust set of libraries.
Later on come back and you will want to learn more about the items below:
Signals and Slots
This is how events are wired together.
One objects sends a signal and all connected slots get called with the given parameters.
Signals and slots are an example of the Observer Pattern.
Designer Forms
The form designer lets you lay out controls using simple drag and drop operations.
The .ui file gets transformed into C++ code as part of the build process.
Layouts
You can do a lot of things with just the horizontal, vertical and grid layouts
Spacers
You can push things up, down, left, or right using different types of spacers
They look like a spring on the form designer.
Resource Files
Lets you embed graphics and other content directly into the application.
Models, Views and Delegates
Hard to avoid if your have a non trivial UI
There are other things too, but knowledge in these areas will let you make some decent desktop applications. My favorite reference is older, but still a goodie: "C++ GUI Programming with Qt4" http://www.amazon.com/Programming-Edition-Prentice-Software-Development/dp/0132354160
Yes QT4 is "old" and QT5 has been out for some time... but the book provides a solid foundation that you will be able to add information to.