diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index ebd813c62e..26bd4c4970 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -35,6 +35,7 @@ Vector Client::s_routes = { { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "title" }, &Client::handle_get_title }, { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "window" }, &Client::handle_get_window_handle }, { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_close_window }, + { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "window", "handles" }, &Client::handle_get_window_handles }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element" }, &Client::handle_find_element }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "elements" }, &Client::handle_find_elements }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element", ":element_id", "element" }, &Client::handle_find_element_from_element }, @@ -431,7 +432,7 @@ ErrorOr Client::handle_get_status(Vector const // 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts // GET /session/{session id}/timeouts -ErrorOr Client::handle_get_timeouts(Vector const& parameters, AK::JsonValue const&) +ErrorOr Client::handle_get_timeouts(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//timeouts"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -441,7 +442,7 @@ ErrorOr Client::handle_get_timeouts(Vector // 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts // POST /session/{session id}/timeouts -ErrorOr Client::handle_set_timeouts(Vector const& parameters, AK::JsonValue const& payload) +ErrorOr Client::handle_set_timeouts(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//timeouts"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -529,6 +530,16 @@ ErrorOr Client::handle_close_window(Vector con return make_json_value(JsonValue()); } +// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles +// GET /session/{session id}/window/handles +ErrorOr Client::handle_get_window_handles(Vector const& parameters, JsonValue const&) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//window/handles"); + auto* session = TRY(find_session_with_id(parameters[0])); + auto result = TRY(session->get_window_handles()); + return make_json_value(result); +} + // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element // POST /session/{session id}/element ErrorOr Client::handle_find_element(Vector const& parameters, JsonValue const& payload) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 16c65f0dd1..630267ea20 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -60,6 +60,7 @@ private: ErrorOr handle_get_title(Vector const&, JsonValue const& payload); ErrorOr handle_get_window_handle(Vector const&, JsonValue const& payload); ErrorOr handle_close_window(Vector const&, JsonValue const& payload); + ErrorOr handle_get_window_handles(Vector const&, JsonValue const& payload); ErrorOr handle_find_element(Vector const&, JsonValue const& payload); ErrorOr handle_find_elements(Vector const&, JsonValue const& payload); ErrorOr handle_find_element_from_element(Vector const&, JsonValue const& payload); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index f953177dfb..306e7b1847 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -269,6 +269,20 @@ ErrorOr> Session::close_window() return {}; } +// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles +ErrorOr Session::get_window_handles() const +{ + // 1. Let handles be a JSON List. + auto handles = JsonArray {}; + + // 2. For each top-level browsing context in the remote end, push the associated window handle onto handles. + for (auto const& window_handle : m_windows.keys()) + handles.append(window_handle); + + // 3. Return success with data handles. + return handles; +} + // https://w3c.github.io/webdriver/#dfn-get-or-create-a-web-element-reference static String get_or_create_a_web_element_reference(Session::LocalElement const& element) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index a35b7981c7..90e6af7fc6 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -48,6 +48,7 @@ public: ErrorOr get_title(); ErrorOr get_window_handle(); ErrorOr> close_window(); + ErrorOr get_window_handles() const; ErrorOr find_element(JsonValue const& payload); ErrorOr find_elements(JsonValue const& payload); ErrorOr find_element_from_element(JsonValue const& payload, StringView parameter_element_id);