mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
WebDriver+Browser: Implement GET /session/{id}/window/rect
This commit is contained in:
parent
7561308af1
commit
dac91c5790
8 changed files with 49 additions and 1 deletions
|
@ -71,6 +71,14 @@ void WebDriverConnection::forward()
|
|||
browser_window->active_tab().go_forward();
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetWindowRectResponse WebDriverConnection::get_window_rect()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_window_rect");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
return { browser_window->rect() };
|
||||
return { {} };
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
virtual void refresh() override;
|
||||
virtual void back() override;
|
||||
virtual void forward() override;
|
||||
virtual Messages::WebDriverSessionClient::GetWindowRectResponse get_window_rect() override;
|
||||
virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
|
||||
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
||||
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <AK/URL.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
|
||||
|
@ -12,6 +13,7 @@ endpoint WebDriverSessionClient {
|
|||
refresh() =|
|
||||
back() =|
|
||||
forward() =|
|
||||
get_window_rect() => (Gfx::IntRect rect)
|
||||
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
|
||||
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
|
||||
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
||||
|
|
|
@ -18,4 +18,4 @@ set(GENERATED_SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(WebDriver)
|
||||
target_link_libraries(WebDriver PRIVATE LibCore LibHTTP LibMain LibIPC LibWeb)
|
||||
target_link_libraries(WebDriver PRIVATE LibCore LibHTTP LibMain LibIPC LibWeb LibGfx)
|
||||
|
|
|
@ -36,6 +36,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ 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::GET, { "session", ":session_id", "window", "rect" }, &Client::handle_get_window_rect },
|
||||
{ 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 },
|
||||
|
@ -543,6 +544,16 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handles(Vector<Stri
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect
|
||||
// GET /session/{session id}/window/rect
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_rect(Vector<StringView> const& parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window/rect");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->get_window_rect());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
|
||||
// POST /session/{session id}/element
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)
|
||||
|
|
|
@ -61,6 +61,7 @@ private:
|
|||
ErrorOr<JsonValue, WebDriverError> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_close_window(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_window_handles(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_window_rect(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_find_element(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <LibCore/LocalServer.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <unistd.h>
|
||||
|
@ -281,6 +282,29 @@ ErrorOr<JsonValue, WebDriverError> Session::get_window_handles() const
|
|||
return handles;
|
||||
}
|
||||
|
||||
static JsonObject serialize_window_rect(Gfx::IntRect const& rect)
|
||||
{
|
||||
JsonObject serialized_rect = {};
|
||||
serialized_rect.set("x", rect.x());
|
||||
serialized_rect.set("y", rect.y());
|
||||
serialized_rect.set("width", rect.width());
|
||||
serialized_rect.set("height", rect.height());
|
||||
|
||||
return serialized_rect;
|
||||
}
|
||||
|
||||
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect
|
||||
ErrorOr<JsonValue, WebDriverError> Session::get_window_rect()
|
||||
{
|
||||
// 1. If the current top-level 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. Return success with data set to the WindowRect object for the current top-level browsing context.
|
||||
return serialize_window_rect(m_browser_connection->get_window_rect());
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
ErrorOr<JsonValue, WebDriverError> get_window_handle();
|
||||
ErrorOr<void, Variant<WebDriverError, Error>> close_window();
|
||||
ErrorOr<JsonValue, WebDriverError> get_window_handles() const;
|
||||
ErrorOr<JsonValue, WebDriverError> get_window_rect();
|
||||
ErrorOr<JsonValue, WebDriverError> find_element(JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> find_elements(JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue