diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-03 12:53:27 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-03 19:15:43 +0000 |
commit | 08c687ef20d9bd718a6baa61c7468a7558d07fdb (patch) | |
tree | 16ef63dd9e712064db1e60474b24e72ed504a712 /Userland/Applications | |
parent | a490bca29b1fe94ff41d34a48a763e6c9951a7fb (diff) | |
download | serenity-08c687ef20d9bd718a6baa61c7468a7558d07fdb.zip |
WebDriver+Browser: Implement `GET /session/{id}/element/{id}/rect`
Diffstat (limited to 'Userland/Applications')
5 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 8f2ec40d0c..aea52c5f95 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -631,6 +631,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate) return active_tab().view().get_element_tag_name(element_id); }; + new_tab.webdriver_endpoints().on_get_element_rect = [this](i32 element_id) { + return active_tab().view().get_element_rect(element_id); + }; + new_tab.webdriver_endpoints().on_serialize_source = [this]() { return active_tab().view().serialize_source(); }; diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index aa4f6ba990..d213269054 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -283,6 +283,17 @@ Messages::WebDriverSessionClient::GetElementTagNameResponse WebDriverConnection: return { "" }; } +Messages::WebDriverSessionClient::GetElementRectResponse WebDriverConnection::get_element_rect(i32 element_id) +{ + dbgln("WebDriverConnection: get_element_rect {}", element_id); + if (auto browser_window = m_browser_window.strong_ref()) { + auto& tab = browser_window->active_tab(); + if (tab.webdriver_endpoints().on_get_element_rect) + return { tab.webdriver_endpoints().on_get_element_rect(element_id) }; + } + return { {} }; +} + Messages::WebDriverSessionClient::TakeScreenshotResponse WebDriverConnection::take_screenshot() { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: take_screenshot"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 6e1af64154..c4415d072c 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -63,6 +63,7 @@ public: virtual Messages::WebDriverSessionClient::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; virtual Messages::WebDriverSessionClient::GetElementTextResponse get_element_text(i32 element_id) override; virtual Messages::WebDriverSessionClient::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; + virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override; virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override; private: diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h index 81f6c4f990..8066e11d69 100644 --- a/Userland/Applications/Browser/WebDriverEndpoints.h +++ b/Userland/Applications/Browser/WebDriverEndpoints.h @@ -8,6 +8,7 @@ #include <AK/Forward.h> #include <AK/Function.h> +#include <LibGfx/Rect.h> #include <LibWeb/Forward.h> namespace Messages::WebContentServer { @@ -29,6 +30,7 @@ public: Function<String(i32 element_id, String const&)> on_get_computed_value_for_element; Function<String(i32 element_id)> on_get_element_text; Function<String(i32 element_id)> on_get_element_tag_name; + Function<Gfx::IntRect(i32 element_id)> on_get_element_rect; Function<String()> on_serialize_source; Function<Messages::WebContentServer::WebdriverExecuteScriptResponse(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)> on_execute_script; }; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 53e67e269d..05e35fa4cc 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -37,5 +37,6 @@ endpoint WebDriverSessionClient { get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) get_element_text(i32 element_id) => (String text) get_element_tag_name(i32 element_id) => (String tag_name) + get_element_rect(i32 element_id) => (Gfx::IntRect rect) take_screenshot() => (Gfx::ShareableBitmap data) } |