Skip to content

Commit

Permalink
Adding support for strictFileInteractability capability in IE
Browse files Browse the repository at this point in the history
The latest editors' drafts of the W3C WebDriver Specification as a living
document have introduce the "strictFileInteractability" capability for
handling <input type='file'> elements. This change makes the driver aware
of that capability.
  • Loading branch information
jimevans committed Nov 11, 2018
1 parent b32e053 commit 0adb38f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
18 changes: 18 additions & 0 deletions cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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.";
Expand Down
7 changes: 5 additions & 2 deletions cpp/iedriver/CommandHandlers/SendKeysCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/IECommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions cpp/iedriver/IECommandExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ class IECommandExecutor : public CWindowImpl<IECommandExecutor>, 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_; }
Expand Down Expand Up @@ -254,6 +261,7 @@ class IECommandExecutor : public CWindowImpl<IECommandExecutor>, 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_;
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/IECommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0adb38f

Please sign in to comment.