Title: [226052] releases/WebKitGTK/webkit-2.18/Source/WebDriver
Revision
226052
Author
carlo...@webkit.org
Date
2017-12-18 09:34:53 -0800 (Mon, 18 Dec 2017)

Log Message

Merge r225474 - WebDriver: implement element property command
https://bugs.webkit.org/show_bug.cgi?id=180244

Reviewed by Brian Burg.

13.3 Get Element Property
https://w3c.github.io/webdriver/webdriver-spec.html#get-element-property

Fixes: imported/w3c/webdriver/tests/state/get_element_property.py::test_no_browsing_context
       imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_dismiss
       imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_accept
       imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_missing_value
       imported/w3c/webdriver/tests/state/get_element_property.py::test_element_stale

* Session.cpp:
(WebDriver::Session::getElementAttribute):
(WebDriver::Session::getElementProperty):
* Session.h:
* WebDriverService.cpp:
(WebDriver::WebDriverService::getElementProperty):
* WebDriverService.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog (226051 => 226052)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog	2017-12-18 17:34:47 UTC (rev 226051)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog	2017-12-18 17:34:53 UTC (rev 226052)
@@ -1,3 +1,27 @@
+2017-12-04  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebDriver: implement element property command
+        https://bugs.webkit.org/show_bug.cgi?id=180244
+
+        Reviewed by Brian Burg.
+
+        13.3 Get Element Property
+        https://w3c.github.io/webdriver/webdriver-spec.html#get-element-property
+
+        Fixes: imported/w3c/webdriver/tests/state/get_element_property.py::test_no_browsing_context
+               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_dismiss
+               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_accept
+               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_missing_value
+               imported/w3c/webdriver/tests/state/get_element_property.py::test_element_stale
+
+        * Session.cpp:
+        (WebDriver::Session::getElementAttribute):
+        (WebDriver::Session::getElementProperty):
+        * Session.h:
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::getElementProperty):
+        * WebDriverService.h:
+
 2017-12-02  Carlos Garcia Campos  <cgar...@igalia.com>
 
         WebDriver: handle user prompts shown while executing scripts

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp (226051 => 226052)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp	2017-12-18 17:34:47 UTC (rev 226051)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp	2017-12-18 17:34:53 UTC (rev 226052)
@@ -1289,6 +1289,47 @@
     });
 }
 
+void Session::getElementProperty(const String& elementID, const String& property, Function<void (CommandResult&&)>&& completionHandler)
+{
+    if (!m_toplevelBrowsingContext) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
+        return;
+    }
+
+    handleUserPrompts([this, elementID, property, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        if (result.isError()) {
+            completionHandler(WTFMove(result));
+            return;
+        }
+        RefPtr<JSON::Array> arguments = JSON::Array::create();
+        arguments->pushString(createElement(elementID)->toJSONString());
+
+        RefPtr<JSON::Object> parameters = JSON::Object::create();
+        parameters->setString(ASCIILiteral("browsingContextHandle"), m_toplevelBrowsingContext.value());
+        if (m_currentBrowsingContext)
+            parameters->setString(ASCIILiteral("frameHandle"), m_currentBrowsingContext.value());
+        parameters->setString(ASCIILiteral("function"), makeString("function(element) { return element.", property, "; }"));
+        parameters->setArray(ASCIILiteral("arguments"), WTFMove(arguments));
+        m_host->sendCommandToBackend(ASCIILiteral("evaluateJavaScriptFunction"), WTFMove(parameters), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
+            if (response.isError || !response.responseObject) {
+                completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
+                return;
+            }
+            String valueString;
+            if (!response.responseObject->getString(ASCIILiteral("result"), valueString)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            RefPtr<JSON::Value> resultValue;
+            if (!JSON::Value::parseJSON(valueString, resultValue)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            completionHandler(CommandResult::success(WTFMove(resultValue)));
+        });
+    });
+}
+
 void Session::waitForNavigationToComplete(Function<void (CommandResult&&)>&& completionHandler)
 {
     if (!m_toplevelBrowsingContext) {

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h (226051 => 226052)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h	2017-12-18 17:34:47 UTC (rev 226051)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h	2017-12-18 17:34:53 UTC (rev 226052)
@@ -87,12 +87,13 @@
     void findElements(const String& strategy, const String& selector, FindElementsMode, const String& rootElementID, Function<void (CommandResult&&)>&&);
     void getActiveElement(Function<void (CommandResult&&)>&&);
     void isElementSelected(const String& elementID, Function<void (CommandResult&&)>&&);
+    void getElementAttribute(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
+    void getElementProperty(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
     void getElementText(const String& elementID, Function<void (CommandResult&&)>&&);
     void getElementTagName(const String& elementID, Function<void (CommandResult&&)>&&);
     void getElementRect(const String& elementID, Function<void (CommandResult&&)>&&);
     void isElementEnabled(const String& elementID, Function<void (CommandResult&&)>&&);
     void isElementDisplayed(const String& elementID, Function<void (CommandResult&&)>&&);
-    void getElementAttribute(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
     void elementClick(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementClear(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementSendKeys(const String& elementID, Vector<String>&& keys, Function<void (CommandResult&&)>&&);

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp (226051 => 226052)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp	2017-12-18 17:34:47 UTC (rev 226051)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp	2017-12-18 17:34:53 UTC (rev 226052)
@@ -127,6 +127,7 @@
 
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/selected", &WebDriverService::isElementSelected },
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/attribute/$name", &WebDriverService::getElementAttribute },
+    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/property/$name", &WebDriverService::getElementProperty },
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/text", &WebDriverService::getElementText },
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/name", &WebDriverService::getElementTagName },
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/rect", &WebDriverService::getElementRect },
@@ -1133,6 +1134,26 @@
     m_session->getElementAttribute(elementID.value(), attribute, WTFMove(completionHandler));
 }
 
+void WebDriverService::getElementProperty(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §13.3 Get Element Property
+    // https://w3c.github.io/webdriver/webdriver-spec.html#get-element-property
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    auto elementID = findElementOrCompleteWithError(*parameters, completionHandler);
+    if (!elementID)
+        return;
+
+    String attribute;
+    if (!parameters->getString(ASCIILiteral("name"), attribute)) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
+        return;
+    }
+
+    m_session->getElementProperty(elementID.value(), attribute, WTFMove(completionHandler));
+}
+
 void WebDriverService::getElementText(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
 {
     // §13.5 Get Element Text.

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h (226051 => 226052)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h	2017-12-18 17:34:47 UTC (rev 226051)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h	2017-12-18 17:34:53 UTC (rev 226052)
@@ -84,12 +84,13 @@
     void findElementsFromElement(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getActiveElement(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void isElementSelected(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
+    void getElementAttribute(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
+    void getElementProperty(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getElementText(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getElementTagName(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getElementRect(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void isElementEnabled(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void isElementDisplayed(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
-    void getElementAttribute(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void elementClick(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void elementClear(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void elementSendKeys(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to