22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- #include < QtGui/QApplication>
6- #include < QtGui/QDesktopWidget>
75#include < QtCore/QEvent>
86#include < QtCore/QThread>
97#include < QtGui/QKeyEvent>
108#include < QtGui/QPixmap>
119#include < QtWebKit/QtWebKit>
1210#include < QtCore/QDebug>
1311#include < QtNetwork/QtNetwork>
12+
13+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
14+ #include < QtWebKitWidgets/QWebFrame>
15+ #include < QtWidgets/QApplication>
16+ #include < QtWidgets/QDesktopWidget>
17+ #include < QtWidgets/QMessageBox>
18+ #include < QtWidgets/QInputDialog>
19+ #else
20+ #include < QtGui/QApplication>
21+ #include < QtGui/QDesktopWidget>
1422#include < QtGui/QMessageBox>
1523#include < QtGui/QInputDialog>
24+ #endif
1625
1726#include " webdriver_automation.h"
1827
@@ -94,11 +103,21 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
94103 if (!options.browser_start_window .empty ())
95104 {
96105 qDebug ()<<" [WD]:" <<" Browser Start Window: " <<options.browser_start_window .c_str ();
106+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
107+ foreach (QWindow* pWidget, qApp->allWindows ())
108+ #else
97109 foreach (QWidget* pWidget, qApp->allWidgets ())
110+ #endif
98111 {
99- qDebug ()<<" [WD]:" <<" looking for start window" <<pWidget<<pWidget->windowTitle ();
112+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
113+ QString title = pWidget->title ();
114+ #else
115+ QString title = pWidget->windowTitle ();
116+ #endif
117+
118+ qDebug () << " [WD]:" << " looking for start window" << pWidget << title;
100119
101- if ((options.browser_start_window == pWidget-> windowTitle () .toStdString ()) || (options.browser_start_window == " *" ))
120+ if ((options.browser_start_window == title .toStdString ()) || (options.browser_start_window == " *" ))
102121 {
103122 QWebView* pView = qobject_cast<QWebView*>(pWidget);
104123 // check found widget if it is QWebView or ancestor; and if it don't belong to any session
@@ -222,10 +241,14 @@ void Automation::Terminate()
222241 qDebug ()<<" [WD]:" <<" *************TERMINATE SESSION******************" ;
223242 logger_.Log (kInfoLogLevel , " QtWebKit WebDriver shutdown" );
224243
244+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
245+ foreach (QWindow* pView, qApp->topLevelWindows ())
246+ #else
225247 foreach (QWidget* pView, qApp->topLevelWidgets ())
248+ #endif
226249 {
227250 QVariant sessionIdVar = pView->property (" sessionId" );
228- if (sessionIdVar.isValid () && (sessionId == sessionIdVar.toInt ()) && ! pView->isHidden ())
251+ if (sessionIdVar.isValid () && (sessionId == sessionIdVar.toInt ()) && pView->isVisible ())
229252 {
230253 // destroy children correctly
231254 QList<QWidget*> childs = pView->findChildren <QWidget*>();
@@ -235,7 +258,9 @@ void Automation::Terminate()
235258 child->close ();
236259 }
237260
261+ #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
238262 pView->setAttribute (Qt::WA_DeleteOnClose, true );
263+ #endif
239264 pView->close ();
240265 }
241266 }
@@ -826,13 +851,17 @@ void Automation::GetViews(std::vector<WebViewInfo>* views,
826851 Error** error)
827852{
828853 std::string extension_id;
854+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
855+ foreach (QWindow* pWidget, qApp->topLevelWindows ())
856+ #else
829857 foreach (QWidget* pWidget, qApp->topLevelWidgets ())
858+ #endif
830859 {
831860 QVariant sessionIdVar = pWidget->property (" sessionId" );
832861 if (sessionIdVar.isValid () && (sessionId == sessionIdVar.toInt ()))
833862 {
834863 QWebView* pView = qobject_cast<QWebView*>(pWidget);
835- if ((pView != NULL ) && ! pView->isHidden ())
864+ if ((pView != NULL ) && pView->isVisible ())
836865 {
837866 WebViewId pWebView = WebViewId::ForQtView (pView);
838867 views->push_back (WebViewInfo (pWebView, extension_id));
@@ -846,7 +875,11 @@ void Automation::DoesViewExist(WebViewId *view_id, bool *does_exist, Error **err
846875 error = NULL ;
847876 *does_exist = false ;
848877
878+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
879+ foreach (QWindow* pWidget, qApp->allWindows ())
880+ #else
849881 foreach (QWidget* pWidget, qApp->allWidgets ())
882+ #endif
850883 {
851884 QVariant sessionIdVar = pWidget->property (" sessionId" );
852885 if (sessionIdVar.isValid () && (sessionId == sessionIdVar.toInt ()))
@@ -1493,7 +1526,11 @@ void Automation::BuildKeyMap()
14931526bool Automation::checkView (const WebViewId &view_id)
14941527{
14951528 // Rework to check only pointer
1529+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
1530+ foreach (QWindow* pView, qApp->allWindows ())
1531+ #else
14961532 foreach (QWidget* pView, qApp->allWidgets ())
1533+ #endif
14971534 {
14981535 QVariant sessionIdVar = pView->property (" sessionId" );
14991536 if (sessionIdVar.isValid () && (sessionId == sessionIdVar.toInt ()))
0 commit comments