Skip to content

Commit

Permalink
Adding pageLoadStrategy to IE driver
Browse files Browse the repository at this point in the history
Setting a capability of pageLoadStrategy when creating a session with the
IE driver will now change the wait behavior when navigating to a new page.
The valid values are:

  "normal" - Waits for document.readyState to be 'complete'. This is the
             default, and is the same behavior as all previous versions of
	     the IE driver.
  "eager"  - Will abort the wait when document.readyState is
             'interactive' instead of waiting for 'complete'.
  "none"   - Will abort the wait immediately, without waiting for any of
             the page to load.

Setting the capability to an invalid value will result in use of the
"normal" page load strategy.
  • Loading branch information
jimevans committed Apr 16, 2015
1 parent 31c89a3 commit 5b9bca3
Show file tree
Hide file tree
Showing 15 changed files with 7,244 additions and 7,168 deletions.
26 changes: 20 additions & 6 deletions cpp/iedriver/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,14 @@ bool Browser::IsBusy() {
return SUCCEEDED(hr) && is_busy == VARIANT_TRUE;
}

bool Browser::Wait() {
bool Browser::Wait(const std::string& page_load_strategy) {
LOG(TRACE) << "Entering Browser::Wait";

if (page_load_strategy == "none") {
LOG(DEBUG) << "Page load strategy is 'none'. Aborting wait.";
this->set_wait_required(false);
return true;
}

bool is_navigating = true;

Expand Down Expand Up @@ -484,7 +490,7 @@ bool Browser::Wait() {
hr = document_dispatch->QueryInterface(&doc);
if (SUCCEEDED(hr)) {
LOG(DEBUG) << "Waiting for document to complete...";
is_navigating = this->IsDocumentNavigating(doc);
is_navigating = this->IsDocumentNavigating(page_load_strategy, doc);
}

if (!is_navigating) {
Expand All @@ -495,7 +501,8 @@ bool Browser::Wait() {
return !is_navigating;
}

bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {
bool Browser::IsDocumentNavigating(const std::string& page_load_strategy,
IHTMLDocument2* doc) {
LOG(TRACE) << "Entering Browser::IsDocumentNavigating";

bool is_navigating = true;
Expand All @@ -504,14 +511,21 @@ bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {
is_navigating = this->is_navigation_started_;
CComBSTR ready_state;
HRESULT hr = doc->get_readyState(&ready_state);
if (FAILED(hr) || is_navigating || _wcsicmp(ready_state, L"complete") != 0) {
if (FAILED(hr) ||
is_navigating ||
_wcsicmp(ready_state, L"complete") != 0 ||
(page_load_strategy == "eager" && _wcsicmp(ready_state, L"interactive") != 0)) {
if (FAILED(hr)) {
LOGHR(DEBUG, hr) << "IHTMLDocument2::get_readyState failed.";
} else if (is_navigating) {
LOG(DEBUG) << "DocumentComplete event fired, indicating a new navigation.";
} else {
std::wstring state = ready_state;
LOG(DEBUG) << "document.readyState is not 'complete'; it was " << LOGWSTRING(state);
if (page_load_strategy == "eager") {
LOG(DEBUG) << "document.readyState is not 'complete' or 'interactive'; it was " << LOGWSTRING(state);
} else {
LOG(DEBUG) << "document.readyState is not 'complete'; it was " << LOGWSTRING(state);
}
}
return true;
} else {
Expand Down Expand Up @@ -565,7 +579,7 @@ bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {

// Recursively call to wait for the frame document to complete
if (is_valid_frame_document) {
is_navigating = this->IsDocumentNavigating(frame_document);
is_navigating = this->IsDocumentNavigating(page_load_strategy, frame_document);
if (is_navigating) {
break;
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/iedriver/Browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
STDMETHOD_(void, OnQuit)();
STDMETHOD_(void, NewWindow3)(IDispatch** ppDisp, VARIANT_BOOL* pbCancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl);

bool Wait(void);
bool Wait(const std::string& page_load_strategy);
void Close(void);
bool IsBusy(void);
void GetDocument(IHTMLDocument2** doc);
Expand Down Expand Up @@ -116,7 +116,8 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
private:
void AttachEvents(void);
void DetachEvents(void);
bool IsDocumentNavigating(IHTMLDocument2* doc);
bool IsDocumentNavigating(const std::string& page_load_strategy,
IHTMLDocument2* doc);
bool GetDocumentFromWindow(IHTMLWindow2* window, IHTMLDocument2** doc);
//HWND GetTabWindowHandle(void);
void CheckDialogType(HWND dialog_window_handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GetSessionCapabilitiesCommandHandler : public IECommandHandler {
}
capabilities[ENABLE_PERSISTENT_HOVER_CAPABILITY] = executor.enable_persistent_hover();
capabilities[UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY] = executor.unexpected_alert_behavior();
capabilities[PAGE_LOAD_STRATEGY_CAPABILITY] = executor.page_load_strategy();
capabilities[ELEMENT_SCROLL_BEHAVIOR_CAPABILITY] = executor.input_manager()->scroll_behavior();
capabilities[IGNORE_PROTECTED_MODE_CAPABILITY] = executor.browser_factory()->ignore_protected_mode_settings();
capabilities[IGNORE_ZOOM_SETTING_CAPABILITY] = executor.browser_factory()->ignore_zoom_setting();
Expand Down
32 changes: 31 additions & 1 deletion cpp/iedriver/CommandHandlers/NewSessionCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class NewSessionCommandHandler : public IECommandHandler {
mutable_executor.set_validate_cookie_document_type(validate_cookie_document_type.asBool());

Json::Value unexpected_alert_behavior = this->GetCapability(it->second, UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY, Json::stringValue, DISMISS_UNEXPECTED_ALERTS);
mutable_executor.set_unexpected_alert_behavior(unexpected_alert_behavior.asString());
mutable_executor.set_unexpected_alert_behavior(this->GetUnexpectedAlertBehaviorValue(unexpected_alert_behavior.asString()));
Json::Value page_load_strategy = this->GetCapability(it->second, PAGE_LOAD_STRATEGY_CAPABILITY, Json::stringValue, NORMAL_PAGE_LOAD_STRATEGY);
mutable_executor.set_page_load_strategy(this->GetPageLoadStrategyValue(page_load_strategy.asString()));
Json::Value enable_element_cache_cleanup = this->GetCapability(it->second, ENABLE_ELEMENT_CACHE_CLEANUP_CAPABILITY, Json::booleanValue, true);
mutable_executor.set_enable_element_cache_cleanup(enable_element_cache_cleanup.asBool());
Json::Value enable_persistent_hover = this->GetCapability(it->second, ENABLE_PERSISTENT_HOVER_CAPABILITY, Json::booleanValue, true);
Expand Down Expand Up @@ -161,6 +163,34 @@ class NewSessionCommandHandler : public IECommandHandler {
}
return "null";
}

std::string NewSessionCommandHandler::GetUnexpectedAlertBehaviorValue(const std::string& desired_value) {
std::string value = DISMISS_UNEXPECTED_ALERTS;
if (desired_value == DISMISS_UNEXPECTED_ALERTS ||
desired_value == ACCEPT_UNEXPECTED_ALERTS ||
desired_value == IGNORE_UNEXPECTED_ALERTS) {
value = desired_value;
} else {
LOG(WARN) << "Desired value of " << desired_value << " for "
<< UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY << " is not"
<< " a valid value. Using default of " << value;
}
return value;
}

std::string NewSessionCommandHandler::GetPageLoadStrategyValue(const std::string& desired_value) {
std::string value = NORMAL_PAGE_LOAD_STRATEGY;
if (desired_value == NORMAL_PAGE_LOAD_STRATEGY ||
desired_value == EAGER_PAGE_LOAD_STRATEGY ||
desired_value == NONE_PAGE_LOAD_STRATEGY) {
value = desired_value;
} else {
LOG(WARN) << "Desired value of " << desired_value << " for "
<< PAGE_LOAD_STRATEGY_CAPABILITY << " is not"
<< " a valid value. Using default of " << value;
}
return value;
}
};

} // namespace webdriver
Expand Down
2 changes: 1 addition & 1 deletion cpp/iedriver/DocumentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DocumentHost {

virtual void GetDocument(IHTMLDocument2** doc) = 0;
virtual void Close(void) = 0;
virtual bool Wait(void) = 0;
virtual bool Wait(const std::string& page_load_strategy) = 0;
virtual bool IsBusy(void) = 0;
virtual HWND GetContentWindowHandle(void) = 0;
virtual HWND GetBrowserWindowHandle(void) = 0;
Expand Down
Loading

0 comments on commit 5b9bca3

Please sign in to comment.