Skip to content

Commit ebce63e

Browse files
Andrii MorozAndrii Moroz
authored andcommitted
Added new command line parameter for WI port
Added support for WI on page switch during session
1 parent bc8c77d commit ebce63e

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

src/chrome/test/webdriver/webdriver_automation.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "chrome/test/webdriver/frame_path.h"
6969
#include "chrome/test/webdriver/webdriver_basic_types.h"
7070
#include "chrome/test/webdriver/webdriver_error.h"
71+
#include "chrome/test/webdriver/webdriver_session_manager.h"
7172
// #include "chrome/test/webdriver/webdriver_util.h"
7273

7374
// #if defined(OS_WIN)
@@ -237,6 +238,8 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
237238
qDebug() << "[WD]: geometry:" << pStartView->geometry();
238239
if (options.command.HasSwitch(switches::kStartMaximized))
239240
pStartView->showMaximized();
241+
242+
pStartView->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
240243

241244
pStartView->show();
242245
}
@@ -669,6 +672,8 @@ void Automation::NavigateToURL(const WebViewId &view_id, const std::string &url,
669672
view->load(address);
670673
if (isLoading)
671674
loop.exec();
675+
676+
view->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
672677
}
673678

674679

@@ -684,6 +689,8 @@ void Automation::NavigateToURLAsync(const WebViewId &view_id, const std::string
684689

685690
QUrl address(QString(url.c_str()));
686691
view->load(address);
692+
693+
view->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
687694
}
688695

689696
void Automation::GoForward(const WebViewId &view_id, Error **error)
@@ -698,6 +705,8 @@ void Automation::GoForward(const WebViewId &view_id, Error **error)
698705

699706
QWebHistory *history = view->history();
700707
history->forward();
708+
709+
view->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
701710
}
702711

703712
void Automation::GoBack(const WebViewId &view_id, Error **error)
@@ -712,6 +721,8 @@ void Automation::GoBack(const WebViewId &view_id, Error **error)
712721

713722
QWebHistory *history = view->history();
714723
history->back();
724+
725+
view->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
715726
}
716727

717728
void Automation::Reload(const WebViewId &view_id, Error **error)
@@ -725,6 +736,8 @@ void Automation::Reload(const WebViewId &view_id, Error **error)
725736
QWebView *view = qobject_cast<QWebView*>(view_id.GetView());
726737

727738
view->reload();
739+
740+
view->page()->setProperty("_q_webInspectorServerPort", SessionManager::GetInstance()->get_wi_port());
728741
}
729742

730743
void Automation::GetCookies(const WebViewId &view_id, const std::string &url, base::ListValue **cookies, Error **error)

src/chrome/test/webdriver/webdriver_server.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ int RunChromeDriver() {
344344
<< " present" << std::endl
345345
<< "config The path to config file (e.g. config.json) in" << std::endl
346346
<< " JSON format with specified WD parameters as" << std::endl
347-
<< " described above (port, root, etc.)" << std::endl;
347+
<< " described above (port, root, etc.)" << std::endl
348+
<< "wi-port 9222 Web inspector listening port" << std::endl;
348349

349350
return (EXIT_SUCCESS);
350351
}
@@ -409,7 +410,9 @@ int RunChromeDriver() {
409410
FilePath log_path;
410411
std::string root = "./web";
411412
std::string url_base;
413+
int wi_port = 9222;
412414
int http_threads = 4;
415+
413416
bool enable_keep_alive = false;
414417
if (cmd_line->HasSwitch("port"))
415418
port = cmd_line->GetSwitchValueASCII("port");
@@ -429,6 +432,9 @@ int RunChromeDriver() {
429432
return 1;
430433
}
431434
}
435+
if (cmd_line->HasSwitch("wi-port"))
436+
wi_port = QString(cmd_line->GetSwitchValueASCII("wi=port").c_str()).toInt();
437+
432438
// if (cmd_line->HasSwitch(kEnableKeepAlive))
433439
// enable_keep_alive = true;
434440

@@ -446,6 +452,7 @@ int RunChromeDriver() {
446452
SessionManager* manager = SessionManager::GetInstance();
447453
manager->set_port(port);
448454
manager->set_url_base(url_base);
455+
manager->set_wi_port(wi_port);
449456

450457
Dispatcher dispatcher(url_base);
451458
InitCallbacks(&dispatcher, &shutdown_event, root.empty());
@@ -481,6 +488,7 @@ int RunChromeDriver() {
481488
<< "root=" << root << std::endl
482489
<< "url-base=" << url_base << std::endl
483490
<< "http-threads=" << http_threads << std::endl
491+
<< "wi-port=" << wi_port << std::endl
484492
/*<< "version=" << chrome::kChromeVersion << std::endl*/;
485493
if (logging_success)
486494
std::cout << "log=" << FileLog::Get()->path().value() << std::endl;
@@ -529,6 +537,7 @@ bool parse_config_to_cmd_line()
529537
std::string url_base;
530538
int http_threads;
531539
std::string log_path;
540+
int wi_port;
532541
if (result_dict->GetInteger("port", &port))
533542
cmd_line->AppendSwitchASCII("port", base::IntToString(port));
534543
if (result_dict->GetString("root", &root))
@@ -539,6 +548,8 @@ bool parse_config_to_cmd_line()
539548
cmd_line->AppendSwitchASCII("http-threads", base::IntToString(http_threads));
540549
if (result_dict->GetString("log-path", &log_path))
541550
cmd_line->AppendSwitchASCII("log-path", log_path);
551+
if (result_dict->GetInteger("wi-port", &wi_port))
552+
cmd_line->AppendSwitchASCII("wi-port", base::IntToString(wi_port));
542553

543554
}
544555
else

src/chrome/test/webdriver/webdriver_session_manager.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ void SessionManager::set_port(const std::string& port) {
4141
port_ = port;
4242
}
4343

44+
void SessionManager::set_wi_port(unsigned int port)
45+
{
46+
wi_port_ = port;
47+
}
48+
4449
void SessionManager::set_url_base(const std::string& url_base) {
4550
url_base_ = url_base;
4651
}
@@ -55,7 +60,11 @@ std::map<std::string, Session*> SessionManager::GetSessions()
5560
return map_;
5661
}
5762

58-
SessionManager::SessionManager() : port_(""), url_base_("") {}
63+
SessionManager::SessionManager()
64+
: port_(""),
65+
url_base_(""),
66+
wi_port_(9222)
67+
{}
5968

6069
SessionManager::~SessionManager() {}
6170

@@ -64,4 +73,9 @@ SessionManager* SessionManager::GetInstance() {
6473
return Singleton<SessionManager>::get();
6574
}
6675

76+
unsigned int SessionManager::get_wi_port() const
77+
{
78+
return wi_port_;
79+
}
80+
6781
} // namespace webdriver

src/chrome/test/webdriver/webdriver_session_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ class SessionManager {
3333
Session* GetSession(const std::string& id) const;
3434

3535
void set_port(const std::string& port);
36+
void set_wi_port(unsigned int port);
3637

3738
void set_url_base(const std::string& url_base);
3839
std::string url_base() const;
3940

4041
std::map<std::string, Session*> GetSessions();
4142

43+
unsigned int get_wi_port() const;
44+
4245
private:
4346
SessionManager();
4447
~SessionManager();
@@ -48,6 +51,7 @@ class SessionManager {
4851
mutable base::Lock map_lock_;
4952
std::string port_;
5053
std::string url_base_;
54+
unsigned int wi_port_;
5155

5256
DISALLOW_COPY_AND_ASSIGN(SessionManager);
5357
};

src/qwebviewext.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ QWebViewExt::~QWebViewExt()
2222
QWebView* QWebViewExt::createWindow(QWebPage::WebWindowType type)
2323
{
2424
QWebViewExt* newView = new QWebViewExt;
25+
newView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
26+
newView->setProperty("_q_webInspectorServerPort", 9222);
2527
newView->show();
2628
newView->setAttribute(Qt::WA_DeleteOnClose, true);
2729
QVariant sessionId = property("sessionId");

0 commit comments

Comments
 (0)