summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonah <jonahshafran@gmail.com>2023-02-19 11:36:08 -0600
committerTim Flynn <trflynn89@pm.me>2023-02-19 13:28:01 -0500
commit30ec59f1632d29eb512357f1d9aed260e04b598a (patch)
tree5064f752f153c1c41bbdd6c7ca39a89b7b0c20ec
parent307cd4a1daa14b9e24221525fa6ae27de0201e95 (diff)
downloadserenity-30ec59f1632d29eb512357f1d9aed260e04b598a.zip
WebDriver: Add computedlabel endpoint
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Client.cpp1
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Client.h1
-rw-r--r--Userland/Services/WebContent/WebDriverClient.ipc1
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.cpp19
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.h1
-rw-r--r--Userland/Services/WebDriver/Client.cpp9
-rw-r--r--Userland/Services/WebDriver/Client.h1
7 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
index 87ed00de11..e3fca074fa 100644
--- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
@@ -87,6 +87,7 @@ static constexpr auto s_webdriver_endpoints = Array {
ROUTE(GET, "/session/:session_id/element/:element_id/rect"sv, get_element_rect),
ROUTE(GET, "/session/:session_id/element/:element_id/enabled"sv, is_element_enabled),
ROUTE(GET, "/session/:session_id/element/:element_id/computedrole"sv, get_computed_role),
+ ROUTE(GET, "/session/:session_id/element/:element_id/computedlabel"sv, get_computed_label),
ROUTE(POST, "/session/:session_id/element/:element_id/click"sv, element_click),
ROUTE(GET, "/session/:session_id/source"sv, get_source),
ROUTE(POST, "/session/:session_id/execute/sync"sv, execute_script),
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.h b/Userland/Libraries/LibWeb/WebDriver/Client.h
index c44edddcc4..2f5776ed29 100644
--- a/Userland/Libraries/LibWeb/WebDriver/Client.h
+++ b/Userland/Libraries/LibWeb/WebDriver/Client.h
@@ -75,6 +75,7 @@ public:
virtual Response get_element_rect(Parameters parameters, JsonValue payload) = 0;
virtual Response is_element_enabled(Parameters parameters, JsonValue payload) = 0;
virtual Response get_computed_role(Parameters parameters, JsonValue payload) = 0;
+ virtual Response get_computed_label(Parameters parameters, JsonValue payload) = 0;
virtual Response element_click(Parameters parameters, JsonValue payload) = 0;
// 13. Document, https://w3c.github.io/webdriver/#document
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc
index afe2e8f868..cadb84b7ce 100644
--- a/Userland/Services/WebContent/WebDriverClient.ipc
+++ b/Userland/Services/WebContent/WebDriverClient.ipc
@@ -41,6 +41,7 @@ endpoint WebDriverClient {
get_element_rect(DeprecatedString element_id) => (Web::WebDriver::Response response)
is_element_enabled(DeprecatedString element_id) => (Web::WebDriver::Response response)
get_computed_role(DeprecatedString element_id) => (Web::WebDriver::Response response)
+ get_computed_label(DeprecatedString element_id) => (Web::WebDriver::Response response)
element_click(DeprecatedString element_id) => (Web::WebDriver::Response response)
get_source() => (Web::WebDriver::Response response)
execute_script(JsonValue payload) => (Web::WebDriver::Response response)
diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp
index 252226ab39..0361199cad 100644
--- a/Userland/Services/WebContent/WebDriverConnection.cpp
+++ b/Userland/Services/WebContent/WebDriverConnection.cpp
@@ -1258,6 +1258,25 @@ Messages::WebDriverClient::GetComputedRoleResponse WebDriverConnection::get_comp
return ""sv;
}
+// 12.4.10 Get Computed Label, https://w3c.github.io/webdriver/#get-computed-label
+Messages::WebDriverClient::GetComputedLabelResponse WebDriverConnection::get_computed_label(DeprecatedString const& element_id)
+{
+ // 1. If the current browsing context is no longer open, return error with error code no such window.
+ TRY(ensure_open_top_level_browsing_context());
+
+ // 2. Handle any user prompts and return its value if it is an error.
+ TRY(handle_any_user_prompts());
+
+ // 3. Let element be the result of trying to get a known element with url variable element id.
+ auto* element = TRY(get_known_connected_element(element_id));
+
+ // 4. Let label be the result of a Accessible Name and Description Computation for the Accessible Name of the element.
+ auto label = element->accessible_name(element->document()).release_value_but_fixme_should_propagate_errors();
+
+ // 5. Return success with data label.
+ return label.to_deprecated_string();
+}
+
// 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click
Messages::WebDriverClient::ElementClickResponse WebDriverConnection::element_click(DeprecatedString const& element_id)
{
diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h
index cf2627e439..e998ebf314 100644
--- a/Userland/Services/WebContent/WebDriverConnection.h
+++ b/Userland/Services/WebContent/WebDriverConnection.h
@@ -76,6 +76,7 @@ private:
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::GetComputedRoleResponse get_computed_role(DeprecatedString const& element_id) override;
+ virtual Messages::WebDriverClient::GetComputedLabelResponse get_computed_label(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::ElementClickResponse element_click(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::GetSourceResponse get_source() override;
virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override;
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp
index cc84d9752d..5556d844cc 100644
--- a/Userland/Services/WebDriver/Client.cpp
+++ b/Userland/Services/WebDriver/Client.cpp
@@ -542,6 +542,15 @@ Web::WebDriver::Response Client::get_computed_role(Web::WebDriver::Parameters pa
return session->web_content_connection().get_computed_role(parameters[1]);
}
+// 12.4.10 Get Computed Label, https://w3c.github.io/webdriver/#get-computed-label
+// GET /session/{session id}/element/{element id}/computedlabel
+Web::WebDriver::Response Client::get_computed_label(Web::WebDriver::Parameters parameters, JsonValue)
+{
+ dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session id>/element/<element id>/computedlabel");
+ auto* session = TRY(find_session_with_id(parameters[0]));
+ return session->web_content_connection().get_computed_label(parameters[1]);
+}
+
// 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click
// POST /session/{session id}/element/{element id}/click
Web::WebDriver::Response Client::element_click(Web::WebDriver::Parameters parameters, JsonValue)
diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h
index ad008a08b6..81c83770c2 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -75,6 +75,7 @@ private:
virtual Web::WebDriver::Response get_element_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response is_element_enabled(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response get_computed_role(Web::WebDriver::Parameters parameters, JsonValue payload) override;
+ virtual Web::WebDriver::Response get_computed_label(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response element_click(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response get_source(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response execute_script(Web::WebDriver::Parameters parameters, JsonValue payload) override;