From 0adb38f9369d151e7b6818314705cdfdffdd2506 Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Sun, 11 Nov 2018 11:56:40 -0800 Subject: [PATCH] Adding support for strictFileInteractability capability in IE The latest editors' drafts of the W3C WebDriver Specification as a living document have introduce the "strictFileInteractability" capability for handling elements. This change makes the driver aware of that capability. --- .../NewSessionCommandHandler.cpp | 18 ++++++++++++++++++ .../CommandHandlers/SendKeysCommandHandler.cpp | 7 +++++-- cpp/iedriver/IECommandExecutor.cpp | 1 + cpp/iedriver/IECommandExecutor.h | 8 ++++++++ cpp/iedriver/IECommandHandler.h | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp b/cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp index 4138859f6e082..63a6e870ffdcf 100644 --- a/cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp +++ b/cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp @@ -455,6 +455,9 @@ void NewSessionCommandHandler::SetInputSettings(const IECommandExecutor& executo mutable_executor.set_file_upload_dialog_timeout(file_upload_dialog_timeout.asInt()); } + Json::Value use_strict_file_interactability = this->GetCapability(capabilities, STRICT_FILE_INTERACTABILITY_CAPABILITY, Json::booleanValue, false); + mutable_executor.set_use_strict_file_interactability(use_strict_file_interactability.asBool()); + Json::Value enable_persistent_hover = this->GetCapability(capabilities, ENABLE_PERSISTENT_HOVER_CAPABILITY, Json::booleanValue, true); if (require_window_focus.asBool() || !enable_native_events.asBool()) { // Setting "require_window_focus" implies SendInput() API, and does not therefore require @@ -474,6 +477,7 @@ Json::Value NewSessionCommandHandler::CreateReturnedCapabilities(const IECommand capabilities[PLATFORM_NAME_CAPABILITY] = "windows"; capabilities[ACCEPT_INSECURE_CERTS_CAPABILITY] = false; capabilities[PAGE_LOAD_STRATEGY_CAPABILITY] = executor.page_load_strategy(); + capabilities[STRICT_FILE_INTERACTABILITY_CAPABILITY] = executor.use_strict_file_interactability(); capabilities[SET_WINDOW_RECT_CAPABILITY] = true; if (executor.unexpected_alert_behavior().size() > 0) { @@ -632,6 +636,20 @@ bool NewSessionCommandHandler::ValidateCapabilities( continue; } + if (capability_name == STRICT_FILE_INTERACTABILITY_CAPABILITY) { + LOG(DEBUG) << "Found " << STRICT_FILE_INTERACTABILITY_CAPABILITY << " capability." + << " Validating value type is boolean."; + if (!this->ValidateCapabilityType(capabilities, + capability_name, + Json::ValueType::booleanValue, + &capability_error_message)) { + *error_message = "Invalid capabilities in " + + capability_set_name + ": " + capability_error_message; + return false; + } + continue; + } + if (capability_name == BROWSER_NAME_CAPABILITY) { LOG(DEBUG) << "Found " << BROWSER_NAME_CAPABILITY << " capability." << " Validating value type is string."; diff --git a/cpp/iedriver/CommandHandlers/SendKeysCommandHandler.cpp b/cpp/iedriver/CommandHandlers/SendKeysCommandHandler.cpp index ea5321c413fa3..e6ddf4ed005bc 100644 --- a/cpp/iedriver/CommandHandlers/SendKeysCommandHandler.cpp +++ b/cpp/iedriver/CommandHandlers/SendKeysCommandHandler.cpp @@ -118,12 +118,13 @@ void SendKeysCommandHandler::ExecuteInternal( &frame_locations); if (this->IsFileUploadElement(element_wrapper)) { + // TODO: If strict file interactability is set on, check element + // interactability before uploading the file. + bool use_strict_file_interactability = executor.use_strict_file_interactability(); this->UploadFile(browser_wrapper, element_wrapper, executor, keys, response); return; } - Json::Value actions = this->CreateActionSequencePayload(executor, &keys); - bool displayed; status_code = element_wrapper->IsDisplayed(true, &displayed); if (status_code != WD_SUCCESS || !displayed) { @@ -151,6 +152,8 @@ void SendKeysCommandHandler::ExecuteInternal( LOG(WARN) << "Specified element is not the active element. Keystrokes may go to an unexpected DOM element."; } + Json::Value actions = this->CreateActionSequencePayload(executor, &keys); + std::string error_info = ""; status_code = executor.input_manager()->PerformInputSequence(browser_wrapper, actions, &error_info); response->SetSuccessResponse(Json::Value::null); diff --git a/cpp/iedriver/IECommandExecutor.cpp b/cpp/iedriver/IECommandExecutor.cpp index d11daf1a6316c..f80d5b19b2349 100755 --- a/cpp/iedriver/IECommandExecutor.cpp +++ b/cpp/iedriver/IECommandExecutor.cpp @@ -94,6 +94,7 @@ LRESULT IECommandExecutor::OnCreate(UINT uMsg, this->is_waiting_ = false; this->is_quitting_ = false; this->is_awaiting_new_window_ = false; + this->use_strict_file_interactability_ = false; this->page_load_strategy_ = "normal"; this->file_upload_dialog_timeout_ = DEFAULT_FILE_UPLOAD_DIALOG_TIMEOUT_IN_MILLISECONDS; diff --git a/cpp/iedriver/IECommandExecutor.h b/cpp/iedriver/IECommandExecutor.h index f3bcbb49213e6..5c9e05699b92d 100755 --- a/cpp/iedriver/IECommandExecutor.h +++ b/cpp/iedriver/IECommandExecutor.h @@ -197,6 +197,13 @@ class IECommandExecutor : public CWindowImpl, public IElement this->file_upload_dialog_timeout_ = file_upload_dialog_timeout; } + bool use_strict_file_interactability(void) const { + return this->use_strict_file_interactability_; + } + void set_use_strict_file_interactability(const bool use_strict_file_interactability) { + this->use_strict_file_interactability_ = use_strict_file_interactability; + } + ElementFinder* element_finder(void) const { return this->element_finder_; } InputManager* input_manager(void) const { return this->input_manager_; } ProxyManager* proxy_manager(void) const { return this->proxy_manager_; } @@ -254,6 +261,7 @@ class IECommandExecutor : public CWindowImpl, public IElement int file_upload_dialog_timeout_; bool use_legacy_file_upload_dialog_handling_; bool enable_full_page_screenshot_; + bool use_strict_file_interactability_; Command current_command_; std::string serialized_response_; diff --git a/cpp/iedriver/IECommandHandler.h b/cpp/iedriver/IECommandHandler.h index c998ab08b7147..8b09e0adb6d67 100755 --- a/cpp/iedriver/IECommandHandler.h +++ b/cpp/iedriver/IECommandHandler.h @@ -35,6 +35,7 @@ #define SET_WINDOW_RECT_CAPABILITY "setWindowRect" #define TIMEOUTS_CAPABILITY "timeouts" #define UNHANDLED_PROMPT_BEHAVIOR_CAPABILITY "unhandledPromptBehavior" +#define STRICT_FILE_INTERACTABILITY_CAPABILITY "strictFileInteractability" #define IE_DRIVER_EXTENSIONS_CAPABILITY "se:ieOptions" #define NATIVE_EVENTS_CAPABILITY "nativeEvents"