From 30ec59f1632d29eb512357f1d9aed260e04b598a Mon Sep 17 00:00:00 2001 From: Jonah Date: Sun, 19 Feb 2023 11:36:08 -0600 Subject: [PATCH] WebDriver: Add computedlabel endpoint --- .../Libraries/LibWeb/WebDriver/Client.cpp | 1 + Userland/Libraries/LibWeb/WebDriver/Client.h | 1 + .../Services/WebContent/WebDriverClient.ipc | 1 + .../WebContent/WebDriverConnection.cpp | 19 +++++++++++++++++++ .../Services/WebContent/WebDriverConnection.h | 1 + Userland/Services/WebDriver/Client.cpp | 9 +++++++++ Userland/Services/WebDriver/Client.h | 1 + 7 files changed, 33 insertions(+) diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp index 87ed00de111..e3fca074fa0 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 c44edddcc4a..2f5776ed298 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 afe2e8f8687..cadb84b7ceb 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 252226ab39b..0361199cad9 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 cf2627e4396..e998ebf3142 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 cc84d9752dc..5556d844cc3 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//element//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 ad008a08b66..81c83770c29 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;