Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1760)

Unified Diff: chrome/test/webdriver/commands/webelement_commands.cc

Issue 6482014: Implement sendKeys webdriver API in ChromeDriver. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/webdriver/commands/webelement_commands.h ('k') | chrome/test/webdriver/server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/commands/webelement_commands.cc
===================================================================
--- chrome/test/webdriver/commands/webelement_commands.cc (revision 73909)
+++ chrome/test/webdriver/commands/webelement_commands.cc (working copy)
@@ -2,20 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/test/webdriver/commands/webelement_command.h"
+#include "chrome/test/webdriver/commands/webelement_commands.h"
-#include "third_party/webdriver/atoms.h"
+#include "base/scoped_ptr.h"
+#include "base/third_party/icu/icu_utf.h"
+#include "base/values.h"
+#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/error_codes.h"
+#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/utility_functions.h"
+#include "third_party/webdriver/atoms.h"
namespace webdriver {
bool WebElementCommand::Init(Response* const response) {
- if (WebDriverCommand::Init(response)) {
- SET_WEBDRIVER_ERROR(response, "Failure on Init for web element command",
- kInternalServerError);
+ if (!WebDriverCommand::Init(response))
return false;
- }
// There should be at least 5 segments to match
// "/session/$session/element/$id"
@@ -82,4 +84,97 @@
dict->GetInteger("height", height);
}
+void ElementValueCommand::ExecuteGet(Response* const response) {
+ Value* unscoped_result = NULL;
+ ListValue args;
+ std::string script = "return arguments[0]['value']";
+ args.Append(GetElementIdAsDictionaryValue(element_id));
+ ErrorCode code =
+ session_->ExecuteScript(script, &args, &unscoped_result);
+ scoped_ptr<Value> result(unscoped_result);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response, "Failed to execute script", code);
+ return;
+ }
+ if (!result->IsType(Value::TYPE_STRING) &&
+ !result->IsType(Value::TYPE_NULL)) {
+ SET_WEBDRIVER_ERROR(response,
+ "Result is not string or null type",
+ kInternalServerError);
+ return;
+ }
+ response->set_status(kSuccess);
+ response->set_value(result.release());
+}
+
+void ElementValueCommand::ExecutePost(Response* const response) {
+ ListValue* key_list;
+ if (!GetListParameter("value", &key_list)) {
+ SET_WEBDRIVER_ERROR(response,
+ "Missing or invalid 'value' parameter",
+ kBadRequest);
+ return;
+ }
+ // Flatten the given array of strings into one.
+ string16 keys;
+ for (size_t i = 0; i < key_list->GetSize(); ++i) {
+ string16 keys_list_part;
+ key_list->GetString(i, &keys_list_part);
+ for (size_t j = 0; j < keys_list_part.size(); ++j) {
+ if (CBU16_IS_SURROGATE(keys_list_part[j])) {
+ SET_WEBDRIVER_ERROR(
+ response,
+ "ChromeDriver only supports characters in the BMP",
+ kBadRequest);
+ return;
+ }
+ }
+ keys.append(keys_list_part);
+ }
+
+ ErrorCode code =
+ session_->SendKeys(GetElementIdAsDictionaryValue(element_id), keys);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response,
+ "Internal SendKeys error",
+ code);
+ return;
+ }
+ response->set_status(kSuccess);
+}
+
+void ElementTextCommand::ExecuteGet(Response* const response) {
+ Value* unscoped_result = NULL;
+ ListValue args;
+ // TODO(jleyba): Use a real javascript atom.
+ std::string script =
+ "function getText(element) {"
+ " if (element instanceof Text) {"
+ " return element.textContent.replace(/^\\s+|\\s+$/g, '');"
+ " }"
+ " var childrenText = '';"
+ " for (var i = 0; i < element.childNodes.length; i++) {"
+ " childrenText += getText(element.childNodes[i]);"
+ " }"
+ " return childrenText;"
+ "}"
+ "return getText(arguments[0]);";
+ args.Append(GetElementIdAsDictionaryValue(element_id));
+ ErrorCode code =
+ session_->ExecuteScript(script, &args, &unscoped_result);
+ scoped_ptr<Value> result(unscoped_result);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response, "Failed to execute script", code);
+ return;
+ }
+ if (!result->IsType(Value::TYPE_STRING)) {
+ SET_WEBDRIVER_ERROR(response,
+ "Result is not string type",
+ kInternalServerError);
+ return;
+ }
+ response->set_status(kSuccess);
+ response->set_value(result.release());
+}
+
} // namespace webdriver
« no previous file with comments | « chrome/test/webdriver/commands/webelement_commands.h ('k') | chrome/test/webdriver/server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698