Skip to content

Commit cef4dc7

Browse files
committed
added 'reuseUI' capability
1 parent fe3cfed commit cef4dc7

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

inc/webdriver_capabilities_parser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ There are two capabilities which define strategy what view will be current after
77
- "windowsize" - HWD will be try create window with given size, as a string (e.g. - "600, 600")
88
- "windowposition" - HWD will be try start window with desired position, as a string (e.g. - "80, 60")
99
- "maximize" - HWD will be try start window with maximum size
10+
- "reuseUI" - HWD checks it of prev session, if those caps not specified,
11+
in case of attempt to create second session we get exeception of "one session only",<br/>
12+
otherwise first session will be terminated without closing windows and new session can reuse that windows
13+
1014
1115
For browserClass customizer can define some generic classes. In example in default
1216
QT extension there is handling of "WidgetView" and "WebView" values for this capability.
@@ -71,6 +75,8 @@ struct Capabilities {
7175
/// start window with maximum size
7276
static const char kMaximize[];
7377

78+
static const char kReuseUI[];
79+
7480
Capabilities();
7581
~Capabilities();
7682

src/webdriver/commands/create_session.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ void CreateSession::ExecutePost(Response* const response) {
4444
// get optional required capabilities
4545
(void)GetDictionaryParameter("requiredCapabilities", &required_caps_dict);
4646

47-
if (SessionManager::GetInstance()->GetSessions().size() > 0) {
48-
response->SetError(new Error(kUnknownError, "Cannot start session. WD support only one session at the moment"));
49-
return;
47+
std::map<std::string, Session*> sessionMap = SessionManager::GetInstance()->GetSessions();
48+
if (sessionMap.size() > 0) {
49+
// session map can consist only single session at the moment
50+
Session* prev_session = sessionMap.begin()->second;
51+
bool reuse_ua;
52+
prev_session->capabilities().caps->GetBoolean(Capabilities::kReuseUI, &reuse_ua);
53+
if (reuse_ua) {
54+
prev_session->Terminate();
55+
} else {
56+
response->SetError(new Error(kUnknownError, "Cannot start session. WD support only one session at the moment"));
57+
return;
58+
}
5059
}
5160

5261
// Session manages its own liftime, so do not call delete.

src/webdriver/webdriver_capabilities_parser.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const char Capabilities::kWindowSize[] = "windowsize";
4545
const char Capabilities::kWindowPosition[] = "windowposition";
4646
const char Capabilities::kMaximize[] = "maximize";
4747
const char Capabilities::kHybrid[] = "hybrid";
48+
const char Capabilities::kReuseUI[] = "reuseUI";
4849

4950
namespace {
5051

src/webdriver/webdriver_session.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ bool Session::InitActualCapabilities() {
9898
hybrid->SetBoolean(*iter, true);
9999
}
100100
capabilities_.caps->Set(Capabilities::kHybrid, hybrid);
101+
102+
bool reuse_ui;
103+
if (required_caps_.get()) {
104+
required_caps_->GetBoolean(Capabilities::kReuseUI, &reuse_ui);
105+
} else if (desired_caps_.get()) {
106+
desired_caps_->GetBoolean(Capabilities::kReuseUI, &reuse_ui);
107+
} else {
108+
reuse_ui = false;
109+
}
110+
capabilities_.caps->SetBoolean(Capabilities::kReuseUI, reuse_ui);
111+
101112
return true;
102113
}
103114

0 commit comments

Comments
 (0)