From 569b56e2adb457abc11f0358d1ced974d934fdaf Mon Sep 17 00:00:00 2001 From: Jonah Date: Sun, 15 Jan 2023 10:26:08 -0600 Subject: [PATCH] WebDriver: Add computedrole 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 69a03277af8..3d1fe7cb1c8 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp @@ -86,6 +86,7 @@ static constexpr auto s_webdriver_endpoints = Array { ROUTE(GET, "/session/:session_id/element/:element_id/name"sv, get_element_tag_name), 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(POST, "/session/:session_id/element/:element_id/click"sv, 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 099c3f63c76..06c5e591e44 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.h +++ b/Userland/Libraries/LibWeb/WebDriver/Client.h @@ -74,6 +74,7 @@ public: virtual Response get_element_tag_name(Parameters parameters, JsonValue payload) = 0; 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 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 277c8e06925..8e646ea3b51 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -40,6 +40,7 @@ endpoint WebDriverClient { get_element_tag_name(DeprecatedString element_id) => (Web::WebDriver::Response response) 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) 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 0359020205d..3edcbc59817 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1172,6 +1172,25 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem return enabled; } +// 12.4.9 Get Computed Role, https://w3c.github.io/webdriver/#dfn-get-computed-role +Messages::WebDriverClient::GetComputedRoleResponse WebDriverConnection::get_computed_role(DeprecatedString const& element_id) +{ + // 1. If the current top-level 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 connected element with url variable element id. + auto* element = TRY(get_known_connected_element(element_id)); + + // 4. Let role be the result of computing the WAI-ARIA role of element. + auto role = element->role_or_default(); + + // 5. Return success with data role. + return DeprecatedString { role }; +} + // 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click Messages::WebDriverClient::ClickResponse WebDriverConnection::click(DeprecatedString const& element_id) { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 40549594300..29e144c7d47 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -75,6 +75,7 @@ private: virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(DeprecatedString const& element_id) override; 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::ClickResponse 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 84bd7eb426b..2e4f7ba9236 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -533,6 +533,15 @@ Web::WebDriver::Response Client::is_element_enabled(Web::WebDriver::Parameters p return session->web_content_connection().is_element_enabled(parameters[1]); } +// 12.4.9 https://w3c.github.io/webdriver/#dfn-get-computed-role +// GET /session/{session id}/element/{element id}/computedrole +Web::WebDriver::Response Client::get_computed_role(Web::WebDriver::Parameters parameters, AK::JsonValue) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//computedrole"); + auto* session = TRY(find_session_with_id(parameters[0])); + return session->web_content_connection().get_computed_role(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::click(Web::WebDriver::Parameters parameters, JsonValue) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index b30ea1f6c5a..27bc0dc78ef 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -75,6 +75,7 @@ private: virtual Web::WebDriver::Response get_element_tag_name(Web::WebDriver::Parameters parameters, JsonValue payload) override; 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 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;