How to resize the Qt Quick Test application window
-
wrote on 24 Jun 2020, 19:27 last edited by Oliver Starke CEOS
Starting my qml test application the test app is shown in a small window (about 100px x100px) by default. I did not find a way to resize it (I would like to have a mximzed window ) since I do not have access to the application window ( or dont know how..) Any ideas ?
PS: I use the QUICK_TEST_MAIN_WITH_SETUP macro to setup some c++ components to be used by the QML TestCases.
ANd I use Qt 5.12 for Windows.in qmlscene I can resize the window to the size of the root item. Does anyone know if/how this is possible within Qt Quick Test framework ?
I searched for a solution the whole afternoon, but without success. Every hint is appreciated !!!
Thanks in advance...
BR
Oliver -
wrote on 26 Jun 2020, 11:48 last edited by
I am now able to resize the window. I implemented my own utility functions which are invokable on qml side (They must be called from qml because the topLevelWindows of QGUiApplication are only available after the window has been created and shown) This is done by the test framework for each test case execution. I attached the corresponding code, if someone has the same requirements while writing gui tests using QMl TestCase. For me this is a basic test utlity function that should be provided by the framework. Perhaps I will create a feature request for this...
class GuiTestUtils : public QObject { Q_OBJECT public: // Utility function to be able to delete files from within a QML test case. Q_INVOKABLE void deleteFile(const QString& fileName) { QFile::remove(fileName); } Q_INVOKABLE void copyFile(const QString& sourceFileName, const QString& destinationFileName) { if(!QFile::copy(sourceFileName, destinationFileName)) { qCritical() << "failed to copy " << sourceFileName << " to " << destinationFileName; } } QWindow* getTestCaseWindow() { QWindowList topLevelWindows = qApp->topLevelWindows(); QWindow* curTestCaseWindow = nullptr; qDebug() << "application name: " << qApp->applicationDisplayName(); qDebug() << "count of TopLevel - windows: " << topLevelWindows.size(); // Todo: find a way to retreive the Filename of the currently loaded qml root item // because the name of the file is the title of the window. for(int i = 0; i < topLevelWindows.size(); ++i) { if(topLevelWindows[i]->title() != "Simulation Output Log") { curTestCaseWindow = topLevelWindows[i]; qDebug() << "found test case top level window : " << curTestCaseWindow->title(); } else { qDebug() << "available top level window [" << i << "] : " << topLevelWindows[i]->title(); } } return curTestCaseWindow; } Q_INVOKABLE void maximizeWindow() { QWindow* curTestCaseWindow = getTestCaseWindow(); if(curTestCaseWindow != nullptr) { curTestCaseWindow->showMaximized(); } } Q_INVOKABLE void minimizeWindow() { QWindow* curTestCaseWindow = getTestCaseWindow(); if(curTestCaseWindow != nullptr) { curTestCaseWindow->showMinimized(); } } };
-
wrote on 26 Jun 2020, 12:20 last edited by
I forgot to mention that a instance of GuiTestUtils is made available to QML using setContextProperty...
1/3