Skip to content

Commit

Permalink
Updating to automatically dismiss onBeforeUnload event dialogs in IE
Browse files Browse the repository at this point in the history
This is a change from previous behavior, where such dialogs were
handled via the standard alert handling commands. The W3C WebDriver
Specification demands that onBeforeUnload dialogs be dismissed
automatically, with no input allowed for the user. This may be a
breaking change for some users who are currently relying on the
alert-handling commands to handle these alerts; however, not
implementing this behavior makes the driver not compliant with the
specificiation. Users in that state will have no choice but to
modify their code to accomodate the new, spec-compliant behavior.
  • Loading branch information
jimevans committed Jul 10, 2018
1 parent 1eaa2d7 commit 8096ef7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 19 deletions.
46 changes: 46 additions & 0 deletions cpp/iedriver/IECommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ LRESULT IECommandExecutor::OnWait(UINT uMsg,
browser->set_wait_required(false);
} else {
this->is_waiting_ = !(browser->Wait(this->page_load_strategy_));
HWND alert_handle = NULL;
if (this->IsAlertActive(browser, &alert_handle)) {
LOG(WARN) << "Found alert";
}
if (this->is_waiting_) {
this->CreateWaitThread(deferred_response);
} else {
Expand Down Expand Up @@ -242,6 +246,38 @@ LRESULT IECommandExecutor::OnBrowserNewWindow(UINT uMsg,
return 0;
}

LRESULT IECommandExecutor::OnBrowserCloseWait(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled) {
LOG(TRACE) << "Entering IECommandExecutor::OnBrowserCloseWait";

LPCSTR str = reinterpret_cast<LPCSTR>(lParam);
std::string browser_id(str);
delete[] str;
BrowserMap::iterator found_iterator = this->managed_browsers_.find(browser_id);
if (found_iterator != this->managed_browsers_.end()) {
// If there's still an alert window active, repost this message to
// ourselves, since the alert will be handled either automatically or
// manually by the user.
HWND alert_handle;
if (this->IsAlertActive(found_iterator->second, &alert_handle)) {
Alert dialog(found_iterator->second, alert_handle);
if (!dialog.is_standard_alert()) {
dialog.Accept();
}
} else {
LPSTR message_payload = new CHAR[browser_id.size() + 1];
strcpy_s(message_payload, browser_id.size() + 1, browser_id.c_str());
::PostMessage(this->m_hWnd,
WD_BROWSER_CLOSE_WAIT,
NULL,
reinterpret_cast<LPARAM>(message_payload));
}
}
return 0;
}

LRESULT IECommandExecutor::OnBrowserQuit(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
Expand Down Expand Up @@ -694,6 +730,16 @@ void IECommandExecutor::DispatchCommand() {
// wait for the browser window to be closed and removed from the
// list of managed browser windows.
LOG(DEBUG) << "Browser is closing; awaiting close.";
LPSTR message_payload = new CHAR[browser->browser_id().size() + 1];
strcpy_s(message_payload,
browser->browser_id().size() + 1,
browser->browser_id().c_str());

::Sleep(WAIT_TIME_IN_MILLISECONDS);
::PostMessage(this->m_hWnd,
WD_BROWSER_CLOSE_WAIT,
NULL,
reinterpret_cast<LPARAM>(message_payload));
this->is_waiting_ = true;
return;
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/iedriver/IECommandExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class IECommandExecutor : public CWindowImpl<IECommandExecutor>, public IElement
MESSAGE_HANDLER(WD_WAIT, OnWait)
MESSAGE_HANDLER(WD_BROWSER_NEW_WINDOW, OnBrowserNewWindow)
MESSAGE_HANDLER(WD_BROWSER_QUIT, OnBrowserQuit)
MESSAGE_HANDLER(WD_BROWSER_CLOSE_WAIT, OnBrowserCloseWait)
MESSAGE_HANDLER(WD_IS_SESSION_VALID, OnIsSessionValid)
MESSAGE_HANDLER(WD_NEW_HTML_DIALOG, OnNewHtmlDialog)
MESSAGE_HANDLER(WD_GET_QUIT_STATUS, OnGetQuitStatus)
Expand All @@ -82,6 +83,7 @@ class IECommandExecutor : public CWindowImpl<IECommandExecutor>, public IElement
LRESULT OnWait(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnBrowserNewWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnBrowserQuit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnBrowserCloseWait(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnIsSessionValid(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnNewHtmlDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnGetQuitStatus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
Expand Down
39 changes: 20 additions & 19 deletions cpp/iedriver/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@
#define WD_SHUTDOWN WM_APP + 15

#define WD_SCRIPT_WAIT WM_APP + 16
#define WD_BROWSER_CLOSE_WAIT WM_APP + 17

#define WD_ASYNC_SCRIPT_SET_DOCUMENT WM_APP + 17
#define WD_ASYNC_SCRIPT_SET_ELEMENT_ARGUMENT WM_APP + 18
#define WD_ASYNC_SCRIPT_SET_POLLING_SCRIPT WM_APP + 19
#define WD_ASYNC_SCRIPT_IS_EXECUTION_READY WM_APP + 20
#define WD_ASYNC_SCRIPT_EXECUTE WM_APP + 21
#define WD_ASYNC_SCRIPT_IS_EXECUTION_COMPLETE WM_APP + 22
#define WD_ASYNC_SCRIPT_GET_RESULT WM_APP + 23
#define WD_ASYNC_SCRIPT_DETACH_LISTENTER WM_APP + 24
#define WD_ASYNC_SCRIPT_GET_REQUIRED_ELEMENT_LIST WM_APP + 25
#define WD_ASYNC_SCRIPT_TRANSFER_MANAGED_ELEMENT WM_APP + 26
#define WD_ASYNC_SCRIPT_NOTIFY_ELEMENT_TRANSFERRED WM_APP + 27
#define WD_ASYNC_SCRIPT_SCHEDULE_REMOVE_MANAGED_ELEMENT WM_APP + 28
#define WD_ASYNC_SCRIPT_SET_DOCUMENT WM_APP + 18
#define WD_ASYNC_SCRIPT_SET_ELEMENT_ARGUMENT WM_APP + 19
#define WD_ASYNC_SCRIPT_SET_POLLING_SCRIPT WM_APP + 20
#define WD_ASYNC_SCRIPT_IS_EXECUTION_READY WM_APP + 21
#define WD_ASYNC_SCRIPT_EXECUTE WM_APP + 22
#define WD_ASYNC_SCRIPT_IS_EXECUTION_COMPLETE WM_APP + 23
#define WD_ASYNC_SCRIPT_GET_RESULT WM_APP + 24
#define WD_ASYNC_SCRIPT_DETACH_LISTENTER WM_APP + 25
#define WD_ASYNC_SCRIPT_GET_REQUIRED_ELEMENT_LIST WM_APP + 26
#define WD_ASYNC_SCRIPT_TRANSFER_MANAGED_ELEMENT WM_APP + 27
#define WD_ASYNC_SCRIPT_NOTIFY_ELEMENT_TRANSFERRED WM_APP + 28
#define WD_ASYNC_SCRIPT_SCHEDULE_REMOVE_MANAGED_ELEMENT WM_APP + 29

#define WD_CHANGE_PROXY WM_APP + 29
#define WD_CHANGE_PROXY WM_APP + 30

#define WD_GET_ALL_COOKIES WM_APP + 30
#define WD_GET_SCRIPTABLE_COOKIES WM_APP + 31
#define WD_GET_HTTPONLY_COOKIES WM_APP + 32
#define WD_GET_SECURE_COOKIES WM_APP + 33
#define WD_GET_COOKIE_CACHE_FILES WM_APP + 34
#define WD_SET_COOKIE WM_APP + 35
#define WD_GET_ALL_COOKIES WM_APP + 31
#define WD_GET_SCRIPTABLE_COOKIES WM_APP + 32
#define WD_GET_HTTPONLY_COOKIES WM_APP + 33
#define WD_GET_SECURE_COOKIES WM_APP + 34
#define WD_GET_COOKIE_CACHE_FILES WM_APP + 35
#define WD_SET_COOKIE WM_APP + 36
16 changes: 16 additions & 0 deletions cpp/iedriverserver/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ available via the project downloads page. Changes in "revision" field indicate
private releases checked into the prebuilts directory of the source tree, but
not made generally available on the downloads page.

v3.13.0.1
=========
* Updated to automatically dismiss onBeforeUnload event dialogs. This is a
change from previous behavior, where such dialogs were handled via the
standard alert handling commands. The W3C WebDriver Specification demands
that onBeforeUnload dialogs be dismissed automatically, with no input
allowed for the user. This may be a breaking change for some users who are
currently relying on the alert-handling commands to handle these alerts;
however, not implementing this behavior makes the driver not compliant with
the specificiation. Users in that state will have no choice but to modify
their code to accomodate the new, spec-compliant behavior.
* Updated the reset action to be spec-compliant. This means that when the
"Release Actions" command is sent, that pressed keystrokes and mouse
buttons are reset to the "up" position in the correct order.
* Corrected "invalid session id" response to be spec-compliant

v3.13.0.0
=========
* Release to synchronize with release of Selenium project.
Expand Down
Binary file modified cpp/prebuilt/Win32/Release/IEDriverServer.exe
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriverServer.exe
Binary file not shown.

0 comments on commit 8096ef7

Please sign in to comment.