diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 0f38927c8a..88a8609c98 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -188,4 +188,15 @@ Messages::WebDriverSessionClient::GetComputedValueForElementResponse WebDriverCo return { "" }; } +Messages::WebDriverSessionClient::GetElementTagNameResponse WebDriverConnection::get_element_tag_name(i32 element_id) +{ + dbgln("WebDriverConnection: get_computed_value_for_element"); + if (auto browser_window = m_browser_window.strong_ref()) { + auto& tab = browser_window->active_tab(); + if (tab.webdriver_endpoints().on_get_element_tag_name) + return { tab.webdriver_endpoints().on_get_element_tag_name(element_id) }; + } + return { "" }; +} + } diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index f87e32541e..8fef50a610 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -53,6 +53,7 @@ public: virtual Messages::WebDriverSessionClient::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override; virtual Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse get_active_documents_type() override; virtual Messages::WebDriverSessionClient::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; + virtual Messages::WebDriverSessionClient::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; private: WebDriverConnection(NonnullOwnPtr socket, NonnullRefPtr browser_window); diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 4896650c76..4dcfbe22c6 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -22,5 +22,6 @@ endpoint WebDriverSessionClient { get_element_property(i32 element_id, String name) => (Optional property) get_active_documents_type() => (String type) get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) + get_element_tag_name(i32 element_id) => (String tag_name) } diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index f27b35531b..24ab6e4c66 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -43,6 +43,7 @@ Vector Client::s_routes = { { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "attribute", ":name" }, &Client::handle_get_element_attribute }, { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "property", ":name" }, &Client::handle_get_element_property }, { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "css", ":property_name" }, &Client::handle_get_element_css_value }, + { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "name" }, &Client::handle_get_element_tag_name }, { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie" }, &Client::handle_get_all_cookies }, { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie", ":name" }, &Client::handle_get_named_cookie }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "cookie" }, &Client::handle_add_cookie }, @@ -611,6 +612,16 @@ ErrorOr Client::handle_get_element_css_value(Vector Client::handle_get_element_tag_name(Vector const& parameters, JsonValue const& payload) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//name"); + auto* session = TRY(find_session_with_id(parameters[0])); + auto result = TRY(session->get_element_tag_name(payload, parameters[1])); + return make_json_value(result); +} + // 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies // GET /session/{session id}/cookie ErrorOr Client::handle_get_all_cookies(Vector const& parameters, JsonValue const&) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index b44b3ff474..3b948176cc 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -68,6 +68,7 @@ private: ErrorOr handle_get_element_attribute(Vector const&, JsonValue const& payload); ErrorOr handle_get_element_property(Vector const&, JsonValue const& payload); ErrorOr handle_get_element_css_value(Vector const&, JsonValue const& payload); + ErrorOr handle_get_element_tag_name(Vector const&, JsonValue const& payload); ErrorOr handle_get_all_cookies(Vector const&, JsonValue const& payload); ErrorOr handle_get_named_cookie(Vector const&, JsonValue const& payload); ErrorOr handle_add_cookie(Vector const&, JsonValue const& payload); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 4d9a424af6..594affebf1 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -711,6 +711,30 @@ ErrorOr Session::get_element_css_value(JsonValue cons return JsonValue(computed_value); } +// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name +ErrorOr Session::get_element_tag_name(JsonValue const&, 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. + + // FIXME: 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 qualified name be the result of getting element’s tagName IDL attribute. + auto qualified_name = m_browser_connection->get_element_tag_name(element_id); + + // 5. Return success with data qualified name. + return JsonValue(qualified_name); +} + // https://w3c.github.io/webdriver/#dfn-serialized-cookie static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index b78bcc1fd4..634933ceab 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -57,6 +57,7 @@ public: ErrorOr get_element_attribute(JsonValue const& payload, StringView element_id, StringView name); ErrorOr get_element_property(JsonValue const& payload, StringView element_id, StringView name); ErrorOr get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name); + ErrorOr get_element_tag_name(JsonValue const& payload, StringView element_id); ErrorOr get_all_cookies(); ErrorOr get_named_cookie(String const& name); ErrorOr add_cookie(JsonValue const& payload);