@@ -109,23 +109,24 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
109109 qsrand (QTime::currentTime ().msec ()+10 );
110110 sessionId = qrand ();
111111
112- QWidget *pStartView = NULL ;
112+ QWebView *pStartView = NULL ;
113113
114114 // Searching for a allready opened window
115115 if (!options.browser_start_window .empty ())
116116 {
117117 qDebug ()<<" [WD]:" <<" Browser Start Window: " <<options.browser_start_window .c_str ();
118- foreach (QWidget* pWidget, qApp->allWidgets ())
118+ foreach (QWidget* pWidget, qApp->topLevelWidgets ())
119119 {
120120
121121 // check found widget if it is QWebView or top level widget
122- if ((pWidget != NULL ) || pWidget->isTopLevel ())
122+ QWebView* pWebView = qobject_cast<QWebView*>(pWidget);
123+ if ((pWebView != NULL ))
123124 {
124125 qDebug ()<<" [WD]:" <<" looking for start window: " <<pWidget<<pWidget->windowTitle ();
125126
126127 if ((options.browser_start_window == pWidget->windowTitle ().toStdString ()) || (options.browser_start_window == " *" ))
127128 {
128- pStartView = pWidget ;
129+ pStartView = pWebView ;
129130
130131 qDebug ()<<" [WD]: found view to attach: " <<pWidget<<pWidget->windowTitle ();
131132
@@ -140,21 +141,15 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
140141 pStartView = ViewFactory::GetInstance ()->create (options.browser_class );
141142
142143 qDebug ()<<" [WD]:" <<" Using window:" <<pStartView;
143- if (pStartView == NULL )
144- {
145- *error = new Error (kBadRequest , " Can't create WebView" );
146- return ;
147- }
148144
149145 // TODO: save proxy settings for further usage
150- QWebView* pWebView = qobject_cast<QWebView*>(pStartView);
151- if (pWebView != NULL )
146+ if (pStartView != NULL )
152147 {
153148 // proxy setup
154149 if (options.command .HasSwitch (switches::kNoProxyServer ))
155150 {
156151 qDebug ()<<" [WD]:" << " No proxy" ;
157- pWebView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::NoProxy));
152+ pStartView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::NoProxy));
158153 }
159154 else if (options.command .HasSwitch (switches::kProxyServer ))
160155 {
@@ -175,7 +170,7 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
175170 if (proxyUrl.isValid () && !proxyUrl.host ().isEmpty ())
176171 {
177172 int proxyPort = (proxyUrl.port () > 0 ) ? proxyUrl.port () : 8080 ;
178- pWebView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyUrl.host (), proxyPort));
173+ pStartView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyUrl.host (), proxyPort));
179174 }
180175 }
181176 }
@@ -199,12 +194,12 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
199194 if (proxyUrl.isValid () && !proxyUrl.host ().isEmpty ())
200195 {
201196 int proxyPort = (proxyUrl.port () > 0 ) ? proxyUrl.port () : 8080 ;
202- pWebView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyUrl.host (), proxyPort));
197+ pStartView ->page ()->networkAccessManager ()->setProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyUrl.host (), proxyPort));
203198 }
204199 }
205200
206- qDebug ()<<" [WD]:" << " hostname = " << pWebView ->page ()->networkAccessManager ()->proxy ().hostName ()
207- << " , port = " << pWebView ->page ()->networkAccessManager ()->proxy ().port ();
201+ qDebug ()<<" [WD]:" << " hostname = " << pStartView ->page ()->networkAccessManager ()->proxy ().hostName ()
202+ << " , port = " << pStartView ->page ()->networkAccessManager ()->proxy ().port ();
208203 }
209204
210205 // handle initial window size and position
0 commit comments