Skip to content

Commit fc5cce3

Browse files
committed
Make IE driver directly return capabilities from new session command
Previously, the driver would return a redirect HTTP response (303), and the language bindings were expected to follow the redirect to get the returned capabilities. This has been an obsolete pattern for some time, and the IE driver is only now conforming to the proper pattern of simply returning a 200 response with the correct capabilities as part of the body.
1 parent 55b964f commit fc5cce3

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

cpp/iedriver/CommandHandlers/NewSessionCommandHandler.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,63 @@ class NewSessionCommandHandler : public IECommandHandler {
3636
void ExecuteInternal(const IECommandExecutor& executor,
3737
const ParametersMap& command_parameters,
3838
Response* response) {
39+
Json::Value returned_capabilities;
40+
returned_capabilities[BROWSER_NAME_CAPABILITY] = "internet explorer";
41+
returned_capabilities[BROWSER_VERSION_CAPABILITY] = std::to_string(static_cast<long long>(executor.browser_version()));
42+
returned_capabilities[JAVASCRIPT_ENABLED_CAPABILITY] = true;
43+
returned_capabilities[PLATFORM_CAPABILITY] = "WINDOWS";
44+
3945
std::string default_initial_url = "http://localhost:" + std::to_string(static_cast<long long>(executor.port())) + "/";
4046
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
4147
ParametersMap::const_iterator it = command_parameters.find("desiredCapabilities");
4248
if (it != command_parameters.end()) {
4349
BrowserFactorySettings factory_settings;
50+
4451
Json::Value ignore_protected_mode_settings = this->GetCapability(it->second, IGNORE_PROTECTED_MODE_CAPABILITY, Json::booleanValue, false);
4552
factory_settings.ignore_protected_mode_settings = ignore_protected_mode_settings.asBool();
53+
returned_capabilities[IGNORE_PROTECTED_MODE_CAPABILITY] = factory_settings.ignore_protected_mode_settings;
54+
4655
Json::Value ignore_zoom_setting = this->GetCapability(it->second, IGNORE_ZOOM_SETTING_CAPABILITY, Json::booleanValue, false);
4756
factory_settings.ignore_zoom_setting = ignore_zoom_setting.asBool();
57+
returned_capabilities[IGNORE_ZOOM_SETTING_CAPABILITY] = factory_settings.ignore_zoom_setting;
58+
4859
Json::Value browser_attach_timeout = this->GetCapability(it->second, BROWSER_ATTACH_TIMEOUT_CAPABILITY, Json::intValue, 0);
4960
factory_settings.browser_attach_timeout = browser_attach_timeout.asInt();
61+
returned_capabilities[BROWSER_ATTACH_TIMEOUT_CAPABILITY] = factory_settings.browser_attach_timeout;
62+
5063
Json::Value initial_url = this->GetCapability(it->second, INITIAL_BROWSER_URL_CAPABILITY, Json::stringValue, default_initial_url);
5164
factory_settings.initial_browser_url = initial_url.asString();
65+
returned_capabilities[INITIAL_BROWSER_URL_CAPABILITY] = factory_settings.initial_browser_url;
66+
5267
Json::Value force_create_process_api = this->GetCapability(it->second, FORCE_CREATE_PROCESS_API_CAPABILITY, Json::booleanValue, false);
5368
factory_settings.force_create_process_api = force_create_process_api.asBool();
69+
returned_capabilities[FORCE_CREATE_PROCESS_API_CAPABILITY] = factory_settings.force_create_process_api;
70+
5471
Json::Value force_shell_windows_api = this->GetCapability(it->second, FORCE_SHELL_WINDOWS_API_CAPABILITY, Json::booleanValue, false);
5572
factory_settings.force_shell_windows_api = force_shell_windows_api.asBool();
73+
returned_capabilities[FORCE_SHELL_WINDOWS_API_CAPABILITY] = factory_settings.force_shell_windows_api;
74+
5675
Json::Value browser_command_line_switches = this->GetCapability(it->second, BROWSER_COMMAND_LINE_SWITCHES_CAPABILITY, Json::stringValue, "");
5776
factory_settings.browser_command_line_switches = browser_command_line_switches.asString();
77+
returned_capabilities[BROWSER_COMMAND_LINE_SWITCHES_CAPABILITY] = factory_settings.browser_command_line_switches;
78+
5879
Json::Value ensure_clean_session = this->GetCapability(it->second, ENSURE_CLEAN_SESSION_CAPABILITY, Json::booleanValue, false);
5980
factory_settings.clear_cache_before_launch = ensure_clean_session.asBool();
81+
returned_capabilities[ENSURE_CLEAN_SESSION_CAPABILITY] = factory_settings.clear_cache_before_launch;
82+
6083
mutable_executor.browser_factory()->Initialize(factory_settings);
6184

6285
Json::Value enable_native_events = this->GetCapability(it->second, NATIVE_EVENTS_CAPABILITY, Json::booleanValue, true);
6386
mutable_executor.input_manager()->set_enable_native_events(enable_native_events.asBool());
87+
returned_capabilities[NATIVE_EVENTS_CAPABILITY] = mutable_executor.input_manager()->enable_native_events();
88+
6489
Json::Value scroll_behavior = this->GetCapability(it->second, ELEMENT_SCROLL_BEHAVIOR_CAPABILITY, Json::intValue, 0);
6590
mutable_executor.input_manager()->set_scroll_behavior(static_cast<ELEMENT_SCROLL_BEHAVIOR>(scroll_behavior.asInt()));
91+
returned_capabilities[ELEMENT_SCROLL_BEHAVIOR_CAPABILITY] = scroll_behavior.asInt();
92+
6693
Json::Value require_window_focus = this->GetCapability(it->second, REQUIRE_WINDOW_FOCUS_CAPABILITY, Json::booleanValue, false);
6794
mutable_executor.input_manager()->set_require_window_focus(require_window_focus.asBool());
95+
returned_capabilities[REQUIRE_WINDOW_FOCUS_CAPABILITY] = mutable_executor.input_manager()->require_window_focus();
6896

6997
Json::Value validate_cookie_document_type = this->GetCapability(it->second, VALIDATE_COOKIE_DOCUMENT_TYPE_CAPABILITY, Json::booleanValue, true);
7098
mutable_executor.set_validate_cookie_document_type(validate_cookie_document_type.asBool());
@@ -73,13 +101,20 @@ class NewSessionCommandHandler : public IECommandHandler {
73101
if (file_upload_dialog_timeout.asInt() > 0) {
74102
mutable_executor.set_file_upload_dialog_timeout(file_upload_dialog_timeout.asInt());
75103
}
104+
returned_capabilities[FILE_UPLOAD_DIALOG_TIMEOUT_CAPABILITY] = mutable_executor.file_upload_dialog_timeout();
76105

77106
Json::Value unexpected_alert_behavior = this->GetCapability(it->second, UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY, Json::stringValue, DISMISS_UNEXPECTED_ALERTS);
78107
mutable_executor.set_unexpected_alert_behavior(this->GetUnexpectedAlertBehaviorValue(unexpected_alert_behavior.asString()));
108+
returned_capabilities[UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY] = executor.unexpected_alert_behavior();
109+
79110
Json::Value page_load_strategy = this->GetCapability(it->second, PAGE_LOAD_STRATEGY_CAPABILITY, Json::stringValue, NORMAL_PAGE_LOAD_STRATEGY);
80111
mutable_executor.set_page_load_strategy(this->GetPageLoadStrategyValue(page_load_strategy.asString()));
112+
returned_capabilities[PAGE_LOAD_STRATEGY_CAPABILITY] = executor.page_load_strategy();
113+
81114
Json::Value enable_element_cache_cleanup = this->GetCapability(it->second, ENABLE_ELEMENT_CACHE_CLEANUP_CAPABILITY, Json::booleanValue, true);
82115
mutable_executor.set_enable_element_cache_cleanup(enable_element_cache_cleanup.asBool());
116+
returned_capabilities[ENABLE_ELEMENT_CACHE_CLEANUP_CAPABILITY] = executor.enable_element_cache_cleanup();
117+
83118
Json::Value enable_persistent_hover = this->GetCapability(it->second, ENABLE_PERSISTENT_HOVER_CAPABILITY, Json::booleanValue, true);
84119
if (require_window_focus.asBool() || !enable_native_events.asBool()) {
85120
// Setting "require_window_focus" implies SendInput() API, and does not therefore require
@@ -88,8 +123,12 @@ class NewSessionCommandHandler : public IECommandHandler {
88123
} else {
89124
mutable_executor.set_enable_persistent_hover(enable_persistent_hover.asBool());
90125
}
126+
returned_capabilities[ENABLE_PERSISTENT_HOVER_CAPABILITY] = executor.enable_persistent_hover();
127+
91128
Json::Value resize_on_screenshot = this->GetCapability(it->second, ENABLE_FULL_PAGE_SCREENSHOT_CAPABILITY, Json::booleanValue, true);
92129
mutable_executor.set_enable_full_page_screenshot(resize_on_screenshot.asBool());
130+
returned_capabilities[ENABLE_FULL_PAGE_SCREENSHOT_CAPABILITY] = executor.enable_full_page_screenshot();
131+
93132
ProxySettings proxy_settings = { false, "", "", "", "", "", "", "", "" };
94133
Json::Value proxy = it->second.get(PROXY_CAPABILITY, Json::nullValue);
95134
if (!proxy.isNull()) {
@@ -118,6 +157,7 @@ class NewSessionCommandHandler : public IECommandHandler {
118157
proxy_settings.use_per_process_proxy = use_per_process_proxy.asBool();
119158
}
120159
mutable_executor.proxy_manager()->Initialize(proxy_settings);
160+
returned_capabilities[PROXY_CAPABILITY] = executor.proxy_manager()->GetProxyAsJson();
121161
}
122162
std::string create_browser_error_message = "";
123163
int result_code = mutable_executor.CreateNewBrowser(&create_browser_error_message);
@@ -130,8 +170,7 @@ class NewSessionCommandHandler : public IECommandHandler {
130170
"Unexpected error launching Internet Explorer. " + create_browser_error_message);
131171
return;
132172
}
133-
std::string id = executor.session_id();
134-
response->SetResponse(303, "/session/" + id);
173+
response->SetNewSessionResponse(executor.session_id(), returned_capabilities);
135174
}
136175

137176
private:

cpp/webdriver-server/response.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ void Response::SetErrorResponse(const int status_code,
7979
this->value_["message"] = message;
8080
}
8181

82+
void Response::SetNewSessionResponse(const std::string& new_session_id,
83+
const Json::Value& response_value) {
84+
LOG(TRACE) << "Entering Response::SetNewSessionResponse";
85+
this->session_id_ = new_session_id;
86+
this->SetResponse(0, response_value);
87+
}
88+
8289
// TODO: This method will be rendered unnecessary once all implementations
8390
// move to string status codes instead of integer status codes. This mapping
8491
// is not entirely correct; it's merely intended as a stopgap.

cpp/webdriver-server/response.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Response {
4141

4242
void SetResponse(const int status_code, const Json::Value& response_value);
4343
void SetSuccessResponse(const Json::Value& response_value);
44+
void SetNewSessionResponse(const std::string& new_session_id,
45+
const Json::Value& response_value);
4446
void SetErrorResponse(const int error_code, const std::string& message);
4547

4648
private:

0 commit comments

Comments
 (0)