Introduction¶
When recording a testscript that opens the systemtray context-menu you will get different recordings depending on the current operating system.
On Linux/X11:
On Windows:
The code interacting with the tray-icon is platform-dependant and works on different objects ("names.Heart_Button
" vs "names.QWidget
"), something which is undesirable for testing cross-platform applications.
Solution¶
Replace the sendEvent
/ mouseClick
that opens the tray-icon context menu with something similar to the following:
This example makes use of the
QSystemTrayIcon
API which is cross-platform. It first tries to lookup the first QSystemTrayIcon
object in the application, fetches the context-menu assigned to the tray-icon followed by opening the context-menu at the current position of the tray-icon.
Alternatively you may use nativeMouseClick()
to achieve a replay that is closer to what a real user would do at the expensive of possible test-instabilities in case the tray-icon unexpectedly changes its position (i.e. appearance of new tray-icons from other applications)
Limitations¶
- The
QSystemTrayIcon
must have been created as a child of some object that can already be found within Squish (i.e. your main window).