WebDriver: implement get element CSS value command
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jan 2018 14:33:32 +0000 (14:33 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jan 2018 14:33:32 +0000 (14:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181736

Reviewed by Carlos Alberto Lopez Perez.

Source/WebDriver:

13.4 Get Element CSS Value
https://w3c.github.io/webdriver/webdriver-spec.html#get-element-css-value

Fixes: imported/selenium/py/test/selenium/webdriver/common/rendered_webelement_tests.py::testShouldPickUpStyleOfAnElement
       imported/selenium/py/test/selenium/webdriver/common/rendered_webelement_tests.py::testShouldAllowInheritedStylesToBeUsed

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

WebDriverTests:

* TestExpectations.json: Unskip tests passing now.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227293 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebDriver/ChangeLog
Source/WebDriver/Session.cpp
Source/WebDriver/Session.h
Source/WebDriver/WebDriverService.cpp
Source/WebDriver/WebDriverService.h
WebDriverTests/ChangeLog
WebDriverTests/TestExpectations.json

index c9e4727..350fd81 100644 (file)
@@ -1,5 +1,26 @@
 2018-01-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        WebDriver: implement get element CSS value command
+        https://bugs.webkit.org/show_bug.cgi?id=181736
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        13.4 Get Element CSS Value
+        https://w3c.github.io/webdriver/webdriver-spec.html#get-element-css-value
+
+        Fixes: imported/selenium/py/test/selenium/webdriver/common/rendered_webelement_tests.py::testShouldPickUpStyleOfAnElement
+               imported/selenium/py/test/selenium/webdriver/common/rendered_webelement_tests.py::testShouldAllowInheritedStylesToBeUsed
+
+        * Session.cpp:
+        (WebDriver::Session::getElementProperty):
+        (WebDriver::Session::getElementCSSValue):
+        * Session.h:
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::getElementCSSValue):
+        * WebDriverService.h:
+
+2018-01-22  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] WebDriver: test imported/w3c/webdriver/tests/sessions/new_session/response.py is crashing in the bots
         https://bugs.webkit.org/show_bug.cgi?id=181904
 
index 3f331cb..1a4240a 100644 (file)
@@ -1363,6 +1363,47 @@ void Session::getElementProperty(const String& elementID, const String& property
     });
 }
 
+void Session::getElementCSSValue(const String& elementID, const String& cssProperty, Function<void (CommandResult&&)>&& completionHandler)
+{
+    if (!m_toplevelBrowsingContext) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
+        return;
+    }
+
+    handleUserPrompts([this, elementID, cssProperty, 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 document.defaultView.getComputedStyle(element).getPropertyValue('", cssProperty, "'); }"));
+        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) {
index 5a8a84e..fbee80b 100644 (file)
@@ -88,6 +88,7 @@ public:
     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 getElementCSSValue(const String& elementID, const String& cssProperty, 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&&)>&&);
index 96501fe..903843d 100644 (file)
@@ -129,6 +129,7 @@ const WebDriverService::Command WebDriverService::s_commands[] = {
     { 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/css/$name", &WebDriverService::getElementCSSValue },
     { 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 },
@@ -1191,6 +1192,26 @@ void WebDriverService::getElementProperty(RefPtr<JSON::Object>&& parameters, Fun
     m_session->getElementProperty(elementID.value(), attribute, WTFMove(completionHandler));
 }
 
+void WebDriverService::getElementCSSValue(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §13.4 Get Element CSS Value
+    // https://w3c.github.io/webdriver/webdriver-spec.html#get-element-css-value
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    auto elementID = findElementOrCompleteWithError(*parameters, completionHandler);
+    if (!elementID)
+        return;
+
+    String cssProperty;
+    if (!parameters->getString(ASCIILiteral("name"), cssProperty)) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
+        return;
+    }
+
+    m_session->getElementCSSValue(elementID.value(), cssProperty, WTFMove(completionHandler));
+}
+
 void WebDriverService::getElementText(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
 {
     // §13.5 Get Element Text.
index d7c6a91..e6b6fbc 100644 (file)
@@ -87,6 +87,7 @@ private:
     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 getElementCSSValue(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&&)>&&);
index 092d769..0fb5dec 100644 (file)
@@ -1,5 +1,14 @@
 2018-01-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        WebDriver: implement get element CSS value command
+        https://bugs.webkit.org/show_bug.cgi?id=181736
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        * TestExpectations.json: Unskip tests passing now.
+
+2018-01-22  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         Unreviewed. Update W3C WebDriver imported tests.
 
         * imported/w3c/importer.json:
index 24f399e..acb079b 100644 (file)
             }
         }
     },
-    "imported/selenium/py/test/selenium/webdriver/common/rendered_webelement_tests.py": {
-        "subtests": {
-            "testShouldPickUpStyleOfAnElement": {
-                "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/181736"}}
-            },
-            "testShouldAllowInheritedStylesToBeUsed": {
-                "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/181736"}}
-            }
-        }
-    },
     "imported/selenium/py/test/selenium/webdriver/common/text_handling_tests.py": {
         "subtests": {
             "testReadALargeAmountOfData": {