本文整理汇总了C++中IECommandExecutor类的典型用法代码示例。如果您正苦于以下问题:C++ IECommandExecutor类的具体用法?C++ IECommandExecutor怎么用?C++ IECommandExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IECommandExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteInternal
void ActionsCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get current browser");
return;
}
ParametersMap::const_iterator actions_parameter_iterator = command_parameters.find("actions");
if (actions_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: actions");
return;
}
if (!actions_parameter_iterator->second.isArray()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Actions value is not an array");
return;
}
std::string error_info = "";
status_code = executor.input_manager()->PerformInputSequence(browser_wrapper,
actions_parameter_iterator->second,
&error_info);
if (status_code != WD_SUCCESS) {
if (status_code == EMOVETARGETOUTOFBOUNDS) {
response->SetErrorResponse(status_code, error_info);
} else {
response->SetErrorResponse(status_code, "Unexpected error performing action sequence.");
}
return;
}
response->SetSuccessResponse(Json::Value::null);
}
示例2: ExecuteInternal
void ScreenshotCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
LOG(TRACE) << "Entering ScreenshotCommandHandler::ExecuteInternal";
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
bool isSameColour = true;
HRESULT hr;
int i = 0;
int tries = 4;
const bool should_resize_window = executor.enable_full_page_screenshot();
do {
this->ClearImage();
this->image_ = new CImage();
if (should_resize_window) {
hr = this->CaptureFullPage(browser_wrapper);
} else {
hr = this->CaptureViewport(browser_wrapper);
}
if (FAILED(hr)) {
LOGHR(WARN, hr) << "Failed to capture browser image at " << i << " try";
this->ClearImage();
response->SetSuccessResponse("");
return;
}
isSameColour = IsSameColour();
if (isSameColour) {
::Sleep(2000);
LOG(DEBUG) << "Failed to capture non single color browser image at " << i << " try";
}
i++;
} while ((i < tries) && isSameColour);
// now either correct or single color image is got
std::string base64_screenshot = "";
hr = this->GetBase64Data(base64_screenshot);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "Unable to transform browser image to Base64 format";
this->ClearImage();
response->SetSuccessResponse("");
return;
}
this->ClearImage();
response->SetSuccessResponse(base64_screenshot);
}
示例3: parent
int IECommandHandler::GetElement(const IECommandExecutor& executor,
const std::string& element_id,
ElementHandle* element_wrapper) {
int status_code = EOBSOLETEELEMENT;
ElementHandle candidate_wrapper;
int result = executor.GetManagedElement(element_id, &candidate_wrapper);
if (result != SUCCESS) {
status_code = 404;
} else {
// Verify that the element is still valid by walking up the
// DOM tree until we find no parent or the html tag
CComPtr<IHTMLElement> parent(candidate_wrapper->element());
while (parent) {
CComQIPtr<IHTMLHtmlElement> html(parent);
if (html) {
status_code = SUCCESS;
*element_wrapper = candidate_wrapper;
break;
}
CComPtr<IHTMLElement> next;
HRESULT hr = parent->get_parentElement(&next);
if (FAILED(hr)) {
//std::cout << hr << " [" << (_bstr_t(_com_error((DWORD) hr).ErrorMessage())) << "]";
}
if (next == NULL) {
BSTR tag;
parent->get_tagName(&tag);
//std::cout << "Found null parent of element with tag " << _bstr_t(tag);
}
parent = next;
}
if (status_code != SUCCESS) {
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
mutable_executor.RemoveManagedElement(element_id);
} else {
// If the element is attached to the DOM, validate that its document
// is the currently-focused document (via frames).
BrowserHandle current_browser;
executor.GetCurrentBrowser(¤t_browser);
CComPtr<IHTMLDocument2> focused_doc;
current_browser->GetDocument(&focused_doc);
CComPtr<IDispatch> parent_doc_dispatch;
parent->get_document(&parent_doc_dispatch);
if (!focused_doc.IsEqualObject(parent_doc_dispatch)) {
status_code = EOBSOLETEELEMENT;
}
}
}
return status_code;
}
示例4: ExecuteInternal
void GetTimeoutsCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
Json::Value response_value;
response_value["implicit"] = executor.implicit_wait_timeout();
response_value["script"] = executor.async_script_timeout();
response_value["pageLoad"] = executor.page_load_timeout();
response->SetSuccessResponse(response_value);
}
示例5: ExecuteInternal
void SetWindowPositionCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("windowHandle");
ParametersMap::const_iterator x_parameter_iterator = command_parameters.find("x");
ParametersMap::const_iterator y_parameter_iterator = command_parameters.find("y");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter in URL: windowHandle");
return;
} else if (x_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: x");
return;
} else if (y_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: y");
return;
} else {
int status_code = WD_SUCCESS;
int x = x_parameter_iterator->second.asInt();
int y = y_parameter_iterator->second.asInt();
std::string window_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
if (window_id == "current") {
status_code = executor.GetCurrentBrowser(&browser_wrapper);
} else {
status_code = executor.GetManagedBrowser(window_id, &browser_wrapper);
}
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Error retrieving window with handle " + window_id);
return;
}
HWND window_handle = browser_wrapper->GetTopLevelWindowHandle();
POINT desired_location;
desired_location.x = x;
desired_location.y = y;
BOOL set_window_pos_result = ::SetWindowPos(window_handle, NULL, desired_location.x, desired_location.y, 0, 0, SWP_NOSIZE);
if (!set_window_pos_result) {
response->SetErrorResponse(EUNHANDLEDERROR,
"Unexpected error setting window size (SetWindowPos API failed)");
return;
}
response->SetSuccessResponse(Json::Value::null);
}
}
示例6: ExecuteInternal
void GetAllCookiesCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
Json::Value response_value(Json::arrayValue);
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
std::vector<BrowserCookie> cookies;
status_code = browser_wrapper->cookie_manager()->GetCookies(
browser_wrapper->GetCurrentUrl(),
&cookies);
if (status_code == EUNHANDLEDERROR) {
std::string error = "Could not retrieve cookies. The most common cause ";
error.append("of this error is a mismatch in the bitness between the ");
error.append("driver and browser. In particular, be sure you are not ");
error.append("attempting to use a 64-bit IEDriverServer.exe against ");
error.append("IE 10 or 11, even on 64-bit Windows.");
response->SetErrorResponse(status_code, error);
return;
}
std::vector<BrowserCookie>::iterator it = cookies.begin();
for (; it != cookies.end(); ++it) {
response_value.append(it->ToJson());
}
response->SetSuccessResponse(response_value);
}
示例7: ExecuteInternal
void IsElementSelectedCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
bool is_selected = element_wrapper->IsSelected();
response->SetSuccessResponse(is_selected);
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例8: ExecuteInternal
void AcceptAlertCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get current browser");
return;
}
// This sleep is required to give IE time to draw the dialog.
::Sleep(100);
HWND alert_handle = browser_wrapper->GetActiveDialogWindowHandle();
if (alert_handle == NULL) {
response->SetErrorResponse(ENOSUCHALERT, "No alert is active");
} else {
Alert dialog(browser_wrapper, alert_handle);
status_code = dialog.Accept();
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code,
"Could not find OK button");
}
// Add sleep to give IE time to close dialog and start Navigation if it's necessary
::Sleep(100);
browser_wrapper->set_wait_required(true);
response->SetSuccessResponse(Json::Value::null);
}
}
示例9: ExecuteInternal
void DeleteCookieCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator name_parameter_iterator = command_parameters.find("name");
if (name_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: name");
return;
}
std::string cookie_name = name_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
BrowserCookie cookie;
cookie.set_name(cookie_name);
browser_wrapper->cookie_manager()->DeleteCookie(
browser_wrapper->GetCurrentUrl(),
cookie);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to delete cookie");
return;
}
response->SetSuccessResponse(Json::Value::null);
}
示例10: LOG
int IECommandHandler::GetElement(const IECommandExecutor& executor,
const std::string& element_id,
ElementHandle* element_wrapper) {
LOG(TRACE) << "Entering IECommandHandler::GetElement";
ElementHandle candidate_wrapper;
int result = executor.GetManagedElement(element_id, &candidate_wrapper);
if (result != SUCCESS) {
// This bears some explanation. Technically, passing an invalid ID in the
// URL for an element command should result in a 404. However, since the
// language bindings don't make up their own element IDs, any call from
// a language binding is more than likely an ID that the IE driver assigned
// it, and it was at one time valid. Therefore, we'll assume that not finding
// the element ID in the cache means it's stale.
LOG(WARN) << "Unable to get managed element, element not found, assuming stale";
return EOBSOLETEELEMENT;
} else {
if (!candidate_wrapper->IsAttachedToDom()) {
LOG(WARN) << "Found managed element is no longer valid";
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
mutable_executor.RemoveManagedElement(element_id);
return EOBSOLETEELEMENT;
} else {
// If the element is attached to the DOM, validate that its document
// is the currently-focused document (via frames).
BrowserHandle current_browser;
executor.GetCurrentBrowser(¤t_browser);
CComPtr<IHTMLDocument2> focused_doc;
current_browser->GetDocument(&focused_doc);
CComPtr<IDispatch> parent_doc_dispatch;
candidate_wrapper->element()->get_document(&parent_doc_dispatch);
if (focused_doc.IsEqualObject(parent_doc_dispatch)) {
*element_wrapper = candidate_wrapper;
return SUCCESS;
} else {
LOG(WARN) << "Found managed element's document is not currently focused";
}
}
}
return EOBSOLETEELEMENT;
}
示例11: ExecuteInternal
void ReleaseActionsCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get current browser");
return;
}
response->SetSuccessResponse(Json::Value::null);
}
示例12: ExecuteInternal
void GetAllWindowHandlesCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
Json::Value handles(Json::arrayValue);
std::vector<std::string> handle_list;
executor.GetManagedBrowserHandles(&handle_list);
for (unsigned int i = 0; i < handle_list.size(); ++i) {
handles.append(handle_list[i]);
}
response->SetSuccessResponse(handles);
}
示例13: ExecuteInternal
void GetElementTextCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
// The atom is just the definition of an anonymous
// function: "function() {...}"; Wrap it in another function so
// we can invoke it with our arguments without polluting the
// current namespace.
std::wstring script_source = L"(function() { return (";
script_source += atoms::asString(atoms::GET_TEXT);
script_source += L")})();";
CComPtr<IHTMLDocument2> doc;
browser_wrapper->GetDocument(&doc);
Script script_wrapper(doc, script_source, 1);
script_wrapper.AddArgument(element_wrapper->element());
status_code = script_wrapper.Execute();
if (status_code == WD_SUCCESS) {
std::string text = "";
bool is_null = script_wrapper.ConvertResultToString(&text);
response->SetSuccessResponse(text);
return;
} else {
response->SetErrorResponse(status_code,
"Unable to get element text");
return;
}
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例14: ExecuteInternal
void GetElementPropertyCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
ParametersMap::const_iterator name_parameter_iterator = command_parameters.find("name");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else if (name_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: name");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
std::string name = name_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
std::string value = "";
bool is_null;
status_code = element_wrapper->GetPropertyValue(name,
&value,
&is_null);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get property");
return;
} else {
if (is_null) {
response->SetSuccessResponse(Json::Value::null);
return;
} else {
response->SetSuccessResponse(value);
return;
}
}
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例15: FindElementUsingSizzle
int ElementFinder::FindElementUsingSizzle(const IECommandExecutor& executor,
const ElementHandle parent_wrapper,
const std::wstring& criteria,
Json::Value* found_element) {
LOG(TRACE) << "Entering ElementFinder::FindElementUsingSizzle";
int result;
BrowserHandle browser;
result = executor.GetCurrentBrowser(&browser);
if (result != WD_SUCCESS) {
LOG(WARN) << "Unable to get browser";
return result;
}
std::wstring script_source(L"(function() { return function(){ if (!window.Sizzle) {");
script_source += atoms::asString(atoms::SIZZLE);
script_source += L"}\n";
script_source += L"var root = arguments[1] ? arguments[1] : document.documentElement;";
script_source += L"if (root['querySelector']) { return root.querySelector(arguments[0]); } ";
script_source += L"var results = []; Sizzle(arguments[0], root, results);";
script_source += L"return results.length > 0 ? results[0] : null;";
script_source += L"};})();";
CComPtr<IHTMLDocument2> doc;
browser->GetDocument(&doc);
Script script_wrapper(doc, script_source, 2);
script_wrapper.AddArgument(criteria);
if (parent_wrapper) {
CComPtr<IHTMLElement> parent(parent_wrapper->element());
script_wrapper.AddArgument(parent);
}
result = script_wrapper.Execute();
if (result == WD_SUCCESS) {
if (!script_wrapper.ResultIsElement()) {
LOG(WARN) << "Found result is not element";
result = ENOSUCHELEMENT;
} else {
result = script_wrapper.ConvertResultToJsonValue(executor,
found_element);
}
} else {
LOG(WARN) << "Unable to find elements";
result = ENOSUCHELEMENT;
}
return result;
}