Skip to content

Commit

Permalink
Merge r225474 - WebDriver: implement element property command
Browse files Browse the repository at this point in the history
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:
  • Loading branch information
carlosgcampos committed Dec 18, 2017
1 parent 0e2e84c commit 96b1ef9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Source/WebDriver/ChangeLog
@@ -1,3 +1,27 @@
2017-12-04 Carlos Garcia Campos <cgarcia@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 <cgarcia@igalia.com>

WebDriver: handle user prompts shown while executing scripts
Expand Down
41 changes: 41 additions & 0 deletions Source/WebDriver/Session.cpp
Expand Up @@ -1289,6 +1289,47 @@ void Session::getElementAttribute(const String& elementID, const String& attribu
});
}

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) {
Expand Down
3 changes: 2 additions & 1 deletion Source/WebDriver/Session.h
Expand Up @@ -87,12 +87,13 @@ class Session : public RefCounted<Session> {
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&&)>&&);
Expand Down
21 changes: 21 additions & 0 deletions Source/WebDriver/WebDriverService.cpp
Expand Up @@ -127,6 +127,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/text", &WebDriverService::getElementText },
{ HTTPMethod::Get, "/session/$sessionId/element/$elementId/name", &WebDriverService::getElementTagName },
{ HTTPMethod::Get, "/session/$sessionId/element/$elementId/rect", &WebDriverService::getElementRect },
Expand Down Expand Up @@ -1133,6 +1134,26 @@ void WebDriverService::getElementAttribute(RefPtr<JSON::Object>&& parameters, Fu
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.
Expand Down
3 changes: 2 additions & 1 deletion Source/WebDriver/WebDriverService.h
Expand Up @@ -84,12 +84,13 @@ class WebDriverService final : public HTTPRequestHandler {
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&&)>&&);
Expand Down

0 comments on commit 96b1ef9

Please sign in to comment.