Skip to content

Commit 5b9bca3

Browse files
committed
Adding pageLoadStrategy to IE driver
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.
1 parent 31c89a3 commit 5b9bca3

15 files changed

+7244
-7168
lines changed

Diff for: cpp/iedriver/Browser.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,14 @@ bool Browser::IsBusy() {
423423
return SUCCEEDED(hr) && is_busy == VARIANT_TRUE;
424424
}
425425

426-
bool Browser::Wait() {
426+
bool Browser::Wait(const std::string& page_load_strategy) {
427427
LOG(TRACE) << "Entering Browser::Wait";
428+
429+
if (page_load_strategy == "none") {
430+
LOG(DEBUG) << "Page load strategy is 'none'. Aborting wait.";
431+
this->set_wait_required(false);
432+
return true;
433+
}
428434

429435
bool is_navigating = true;
430436

@@ -484,7 +490,7 @@ bool Browser::Wait() {
484490
hr = document_dispatch->QueryInterface(&doc);
485491
if (SUCCEEDED(hr)) {
486492
LOG(DEBUG) << "Waiting for document to complete...";
487-
is_navigating = this->IsDocumentNavigating(doc);
493+
is_navigating = this->IsDocumentNavigating(page_load_strategy, doc);
488494
}
489495

490496
if (!is_navigating) {
@@ -495,7 +501,8 @@ bool Browser::Wait() {
495501
return !is_navigating;
496502
}
497503

498-
bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {
504+
bool Browser::IsDocumentNavigating(const std::string& page_load_strategy,
505+
IHTMLDocument2* doc) {
499506
LOG(TRACE) << "Entering Browser::IsDocumentNavigating";
500507

501508
bool is_navigating = true;
@@ -504,14 +511,21 @@ bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {
504511
is_navigating = this->is_navigation_started_;
505512
CComBSTR ready_state;
506513
HRESULT hr = doc->get_readyState(&ready_state);
507-
if (FAILED(hr) || is_navigating || _wcsicmp(ready_state, L"complete") != 0) {
514+
if (FAILED(hr) ||
515+
is_navigating ||
516+
_wcsicmp(ready_state, L"complete") != 0 ||
517+
(page_load_strategy == "eager" && _wcsicmp(ready_state, L"interactive") != 0)) {
508518
if (FAILED(hr)) {
509519
LOGHR(DEBUG, hr) << "IHTMLDocument2::get_readyState failed.";
510520
} else if (is_navigating) {
511521
LOG(DEBUG) << "DocumentComplete event fired, indicating a new navigation.";
512522
} else {
513523
std::wstring state = ready_state;
514-
LOG(DEBUG) << "document.readyState is not 'complete'; it was " << LOGWSTRING(state);
524+
if (page_load_strategy == "eager") {
525+
LOG(DEBUG) << "document.readyState is not 'complete' or 'interactive'; it was " << LOGWSTRING(state);
526+
} else {
527+
LOG(DEBUG) << "document.readyState is not 'complete'; it was " << LOGWSTRING(state);
528+
}
515529
}
516530
return true;
517531
} else {
@@ -565,7 +579,7 @@ bool Browser::IsDocumentNavigating(IHTMLDocument2* doc) {
565579

566580
// Recursively call to wait for the frame document to complete
567581
if (is_valid_frame_document) {
568-
is_navigating = this->IsDocumentNavigating(frame_document);
582+
is_navigating = this->IsDocumentNavigating(page_load_strategy, frame_document);
569583
if (is_navigating) {
570584
break;
571585
}

Diff for: cpp/iedriver/Browser.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
8787
STDMETHOD_(void, OnQuit)();
8888
STDMETHOD_(void, NewWindow3)(IDispatch** ppDisp, VARIANT_BOOL* pbCancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl);
8989

90-
bool Wait(void);
90+
bool Wait(const std::string& page_load_strategy);
9191
void Close(void);
9292
bool IsBusy(void);
9393
void GetDocument(IHTMLDocument2** doc);
@@ -116,7 +116,8 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
116116
private:
117117
void AttachEvents(void);
118118
void DetachEvents(void);
119-
bool IsDocumentNavigating(IHTMLDocument2* doc);
119+
bool IsDocumentNavigating(const std::string& page_load_strategy,
120+
IHTMLDocument2* doc);
120121
bool GetDocumentFromWindow(IHTMLWindow2* window, IHTMLDocument2** doc);
121122
//HWND GetTabWindowHandle(void);
122123
void CheckDialogType(HWND dialog_window_handle);

Diff for: cpp/iedriver/CommandHandlers/GetSessionCapabilitiesCommandHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GetSessionCapabilitiesCommandHandler : public IECommandHandler {
4949
}
5050
capabilities[ENABLE_PERSISTENT_HOVER_CAPABILITY] = executor.enable_persistent_hover();
5151
capabilities[UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY] = executor.unexpected_alert_behavior();
52+
capabilities[PAGE_LOAD_STRATEGY_CAPABILITY] = executor.page_load_strategy();
5253
capabilities[ELEMENT_SCROLL_BEHAVIOR_CAPABILITY] = executor.input_manager()->scroll_behavior();
5354
capabilities[IGNORE_PROTECTED_MODE_CAPABILITY] = executor.browser_factory()->ignore_protected_mode_settings();
5455
capabilities[IGNORE_ZOOM_SETTING_CAPABILITY] = executor.browser_factory()->ignore_zoom_setting();

Diff for: cpp/iedriver/CommandHandlers/NewSessionCommandHandler.h

+31-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class NewSessionCommandHandler : public IECommandHandler {
7070
mutable_executor.set_validate_cookie_document_type(validate_cookie_document_type.asBool());
7171

7272
Json::Value unexpected_alert_behavior = this->GetCapability(it->second, UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY, Json::stringValue, DISMISS_UNEXPECTED_ALERTS);
73-
mutable_executor.set_unexpected_alert_behavior(unexpected_alert_behavior.asString());
73+
mutable_executor.set_unexpected_alert_behavior(this->GetUnexpectedAlertBehaviorValue(unexpected_alert_behavior.asString()));
74+
Json::Value page_load_strategy = this->GetCapability(it->second, PAGE_LOAD_STRATEGY_CAPABILITY, Json::stringValue, NORMAL_PAGE_LOAD_STRATEGY);
75+
mutable_executor.set_page_load_strategy(this->GetPageLoadStrategyValue(page_load_strategy.asString()));
7476
Json::Value enable_element_cache_cleanup = this->GetCapability(it->second, ENABLE_ELEMENT_CACHE_CLEANUP_CAPABILITY, Json::booleanValue, true);
7577
mutable_executor.set_enable_element_cache_cleanup(enable_element_cache_cleanup.asBool());
7678
Json::Value enable_persistent_hover = this->GetCapability(it->second, ENABLE_PERSISTENT_HOVER_CAPABILITY, Json::booleanValue, true);
@@ -161,6 +163,34 @@ class NewSessionCommandHandler : public IECommandHandler {
161163
}
162164
return "null";
163165
}
166+
167+
std::string NewSessionCommandHandler::GetUnexpectedAlertBehaviorValue(const std::string& desired_value) {
168+
std::string value = DISMISS_UNEXPECTED_ALERTS;
169+
if (desired_value == DISMISS_UNEXPECTED_ALERTS ||
170+
desired_value == ACCEPT_UNEXPECTED_ALERTS ||
171+
desired_value == IGNORE_UNEXPECTED_ALERTS) {
172+
value = desired_value;
173+
} else {
174+
LOG(WARN) << "Desired value of " << desired_value << " for "
175+
<< UNEXPECTED_ALERT_BEHAVIOR_CAPABILITY << " is not"
176+
<< " a valid value. Using default of " << value;
177+
}
178+
return value;
179+
}
180+
181+
std::string NewSessionCommandHandler::GetPageLoadStrategyValue(const std::string& desired_value) {
182+
std::string value = NORMAL_PAGE_LOAD_STRATEGY;
183+
if (desired_value == NORMAL_PAGE_LOAD_STRATEGY ||
184+
desired_value == EAGER_PAGE_LOAD_STRATEGY ||
185+
desired_value == NONE_PAGE_LOAD_STRATEGY) {
186+
value = desired_value;
187+
} else {
188+
LOG(WARN) << "Desired value of " << desired_value << " for "
189+
<< PAGE_LOAD_STRATEGY_CAPABILITY << " is not"
190+
<< " a valid value. Using default of " << value;
191+
}
192+
return value;
193+
}
164194
};
165195

166196
} // namespace webdriver

Diff for: cpp/iedriver/DocumentHost.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DocumentHost {
3434

3535
virtual void GetDocument(IHTMLDocument2** doc) = 0;
3636
virtual void Close(void) = 0;
37-
virtual bool Wait(void) = 0;
37+
virtual bool Wait(const std::string& page_load_strategy) = 0;
3838
virtual bool IsBusy(void) = 0;
3939
virtual HWND GetContentWindowHandle(void) = 0;
4040
virtual HWND GetBrowserWindowHandle(void) = 0;

0 commit comments

Comments
 (0)