WebDriver: Add computedrole endpoint

This commit is contained in:
Jonah 2023-01-15 10:26:08 -06:00 committed by Tim Flynn
parent 3fb4d50982
commit 569b56e2ad
Notes: sideshowbarker 2024-07-17 01:36:05 +09:00
7 changed files with 33 additions and 0 deletions

View file

@ -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/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/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/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(POST, "/session/:session_id/element/:element_id/click"sv, click),
ROUTE(GET, "/session/:session_id/source"sv, get_source), ROUTE(GET, "/session/:session_id/source"sv, get_source),
ROUTE(POST, "/session/:session_id/execute/sync"sv, execute_script), ROUTE(POST, "/session/:session_id/execute/sync"sv, execute_script),

View file

@ -74,6 +74,7 @@ public:
virtual Response get_element_tag_name(Parameters parameters, JsonValue payload) = 0; virtual Response get_element_tag_name(Parameters parameters, JsonValue payload) = 0;
virtual Response get_element_rect(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 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; virtual Response click(Parameters parameters, JsonValue payload) = 0;
// 13. Document, https://w3c.github.io/webdriver/#document // 13. Document, https://w3c.github.io/webdriver/#document

View file

@ -40,6 +40,7 @@ endpoint WebDriverClient {
get_element_tag_name(DeprecatedString element_id) => (Web::WebDriver::Response response) get_element_tag_name(DeprecatedString element_id) => (Web::WebDriver::Response response)
get_element_rect(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) 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) click(DeprecatedString element_id) => (Web::WebDriver::Response response)
get_source() => (Web::WebDriver::Response response) get_source() => (Web::WebDriver::Response response)
execute_script(JsonValue payload) => (Web::WebDriver::Response response) execute_script(JsonValue payload) => (Web::WebDriver::Response response)

View file

@ -1172,6 +1172,25 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem
return enabled; 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 // 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click
Messages::WebDriverClient::ClickResponse WebDriverConnection::click(DeprecatedString const& element_id) Messages::WebDriverClient::ClickResponse WebDriverConnection::click(DeprecatedString const& element_id)
{ {

View file

@ -75,6 +75,7 @@ private:
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(DeprecatedString const& element_id) override; 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::GetElementRectResponse get_element_rect(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(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::ClickResponse click(DeprecatedString const& element_id) override;
virtual Messages::WebDriverClient::GetSourceResponse get_source() override; virtual Messages::WebDriverClient::GetSourceResponse get_source() override;
virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override; virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override;

View file

@ -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]); 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/<session id>/element/<element id>/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 // 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click
// POST /session/{session id}/element/{element id}/click // POST /session/{session id}/element/{element id}/click
Web::WebDriver::Response Client::click(Web::WebDriver::Parameters parameters, JsonValue) Web::WebDriver::Response Client::click(Web::WebDriver::Parameters parameters, JsonValue)

View file

@ -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_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 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 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 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 get_source(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response execute_script(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response execute_script(Web::WebDriver::Parameters parameters, JsonValue payload) override;