1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:07:44 +00:00

WebDriver+Browser: Implement GET /session/{id}/element/{id}/enabled

This commit is contained in:
Timothy Flynn 2022-11-03 13:31:08 -04:00 committed by Linus Groh
parent 683c99f299
commit 0f2b4d0aac
9 changed files with 64 additions and 0 deletions

View file

@ -3,6 +3,7 @@
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -50,6 +51,7 @@ Vector<Client::Route> Client::s_routes = {
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "text" }, &Client::handle_get_element_text },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "name" }, &Client::handle_get_element_tag_name },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "rect" }, &Client::handle_get_element_rect },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "enabled" }, &Client::handle_is_element_enabled },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "source" }, &Client::handle_get_source },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "execute", "sync" }, &Client::handle_execute_script },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "execute", "async" }, &Client::handle_execute_async_script },
@ -699,6 +701,16 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_rect(Vector<String
return make_json_value(result);
}
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
// GET /session/{session id}/element/{element id}/enabled
ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_enabled(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/enabled");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->is_element_enabled(parameters[1]));
return make_json_value(result);
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
// GET /session/{session id}/source
ErrorOr<JsonValue, WebDriverError> Client::handle_get_source(Vector<StringView> const& parameters, JsonValue const&)

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -75,6 +76,7 @@ private:
ErrorOr<JsonValue, WebDriverError> handle_get_element_text(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_element_tag_name(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_element_rect(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_is_element_enabled(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_source(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_execute_script(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_execute_async_script(Vector<StringView> const&, JsonValue const& payload);

View file

@ -3,6 +3,7 @@
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -936,6 +937,32 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_rect(StringView paramete
return body;
}
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
ErrorOr<JsonValue, WebDriverError> Session::is_element_enabled(StringView parameter_element_id)
{
// 1. If the current browsing context is no longer open, return error with error code no such window.
TRY(check_for_open_top_level_browsing_context_or_return_error());
// FIXME: 2. Handle any user prompts and return its value if it is an error.
// 3. Let element be the result of trying to get a known connected element with url variable element id.
// NOTE: The whole concept of "connected elements" is not implemented yet. See get_or_create_a_web_element_reference()
// For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value();
// 4. Let enabled be a boolean initially set to true if the current browsing contexts active documents type is not "xml".
// 5. Otherwise, let enabled to false and jump to the last step of this algorithm.
// 6. Set enabled to false if a form control is disabled.
auto enabled = m_browser_connection->is_element_enabled(element_id);
// 7. Return success with data enabled.
return enabled;
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
ErrorOr<JsonValue, WebDriverError> Session::get_source()
{

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -64,6 +65,7 @@ public:
ErrorOr<JsonValue, WebDriverError> get_element_text(JsonValue const& payload, StringView element_id);
ErrorOr<JsonValue, WebDriverError> get_element_tag_name(JsonValue const& payload, StringView element_id);
ErrorOr<JsonValue, WebDriverError> get_element_rect(StringView element_id);
ErrorOr<JsonValue, WebDriverError> is_element_enabled(StringView element_id);
ErrorOr<JsonValue, WebDriverError> get_source();
ErrorOr<JsonValue, WebDriverError> execute_script(JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> execute_async_script(JsonValue const& payload);