Changeset 226052 in webkit


Ignore:
Timestamp:
Dec 18, 2017 9:34:53 AM (6 years ago)
Author:
Carlos Garcia Campos
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:
Location:
releases/WebKitGTK/webkit-2.18/Source/WebDriver
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog

    r226051 r226052  
     12017-12-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        WebDriver: implement element property command
     4        https://bugs.webkit.org/show_bug.cgi?id=180244
     5
     6        Reviewed by Brian Burg.
     7
     8        13.3 Get Element Property
     9        https://w3c.github.io/webdriver/webdriver-spec.html#get-element-property
     10
     11        Fixes: imported/w3c/webdriver/tests/state/get_element_property.py::test_no_browsing_context
     12               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_dismiss
     13               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_accept
     14               imported/w3c/webdriver/tests/state/get_element_property.py::test_handle_prompt_missing_value
     15               imported/w3c/webdriver/tests/state/get_element_property.py::test_element_stale
     16
     17        * Session.cpp:
     18        (WebDriver::Session::getElementAttribute):
     19        (WebDriver::Session::getElementProperty):
     20        * Session.h:
     21        * WebDriverService.cpp:
     22        (WebDriver::WebDriverService::getElementProperty):
     23        * WebDriverService.h:
     24
    1252017-12-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    226
  • releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp

    r226051 r226052  
    12691269            parameters->setString(ASCIILiteral("frameHandle"), m_currentBrowsingContext.value());
    12701270        parameters->setString(ASCIILiteral("function"), ElementAttributeJavaScript);
     1271        parameters->setArray(ASCIILiteral("arguments"), WTFMove(arguments));
     1272        m_host->sendCommandToBackend(ASCIILiteral("evaluateJavaScriptFunction"), WTFMove(parameters), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
     1273            if (response.isError || !response.responseObject) {
     1274                completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
     1275                return;
     1276            }
     1277            String valueString;
     1278            if (!response.responseObject->getString(ASCIILiteral("result"), valueString)) {
     1279                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
     1280                return;
     1281            }
     1282            RefPtr<JSON::Value> resultValue;
     1283            if (!JSON::Value::parseJSON(valueString, resultValue)) {
     1284                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
     1285                return;
     1286            }
     1287            completionHandler(CommandResult::success(WTFMove(resultValue)));
     1288        });
     1289    });
     1290}
     1291
     1292void Session::getElementProperty(const String& elementID, const String& property, Function<void (CommandResult&&)>&& completionHandler)
     1293{
     1294    if (!m_toplevelBrowsingContext) {
     1295        completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
     1296        return;
     1297    }
     1298
     1299    handleUserPrompts([this, elementID, property, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
     1300        if (result.isError()) {
     1301            completionHandler(WTFMove(result));
     1302            return;
     1303        }
     1304        RefPtr<JSON::Array> arguments = JSON::Array::create();
     1305        arguments->pushString(createElement(elementID)->toJSONString());
     1306
     1307        RefPtr<JSON::Object> parameters = JSON::Object::create();
     1308        parameters->setString(ASCIILiteral("browsingContextHandle"), m_toplevelBrowsingContext.value());
     1309        if (m_currentBrowsingContext)
     1310            parameters->setString(ASCIILiteral("frameHandle"), m_currentBrowsingContext.value());
     1311        parameters->setString(ASCIILiteral("function"), makeString("function(element) { return element.", property, "; }"));
    12711312        parameters->setArray(ASCIILiteral("arguments"), WTFMove(arguments));
    12721313        m_host->sendCommandToBackend(ASCIILiteral("evaluateJavaScriptFunction"), WTFMove(parameters), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
  • releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h

    r226051 r226052  
    8888    void getActiveElement(Function<void (CommandResult&&)>&&);
    8989    void isElementSelected(const String& elementID, Function<void (CommandResult&&)>&&);
     90    void getElementAttribute(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
     91    void getElementProperty(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
    9092    void getElementText(const String& elementID, Function<void (CommandResult&&)>&&);
    9193    void getElementTagName(const String& elementID, Function<void (CommandResult&&)>&&);
     
    9395    void isElementEnabled(const String& elementID, Function<void (CommandResult&&)>&&);
    9496    void isElementDisplayed(const String& elementID, Function<void (CommandResult&&)>&&);
    95     void getElementAttribute(const String& elementID, const String& attribute, Function<void (CommandResult&&)>&&);
    9697    void elementClick(const String& elementID, Function<void (CommandResult&&)>&&);
    9798    void elementClear(const String& elementID, Function<void (CommandResult&&)>&&);
  • releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp

    r226046 r226052  
    128128    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/selected", &WebDriverService::isElementSelected },
    129129    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/attribute/$name", &WebDriverService::getElementAttribute },
     130    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/property/$name", &WebDriverService::getElementProperty },
    130131    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/text", &WebDriverService::getElementText },
    131132    { HTTPMethod::Get, "/session/$sessionId/element/$elementId/name", &WebDriverService::getElementTagName },
     
    11341135}
    11351136
     1137void WebDriverService::getElementProperty(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
     1138{
     1139    // §13.3 Get Element Property
     1140    // https://w3c.github.io/webdriver/webdriver-spec.html#get-element-property
     1141    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
     1142        return;
     1143
     1144    auto elementID = findElementOrCompleteWithError(*parameters, completionHandler);
     1145    if (!elementID)
     1146        return;
     1147
     1148    String attribute;
     1149    if (!parameters->getString(ASCIILiteral("name"), attribute)) {
     1150        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
     1151        return;
     1152    }
     1153
     1154    m_session->getElementProperty(elementID.value(), attribute, WTFMove(completionHandler));
     1155}
     1156
    11361157void WebDriverService::getElementText(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
    11371158{
  • releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h

    r226046 r226052  
    8585    void getActiveElement(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    8686    void isElementSelected(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     87    void getElementAttribute(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     88    void getElementProperty(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    8789    void getElementText(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    8890    void getElementTagName(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     
    9092    void isElementEnabled(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    9193    void isElementDisplayed(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    92     void getElementAttribute(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    9394    void elementClick(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
    9495    void elementClear(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
Note: See TracChangeset for help on using the changeset viewer.