mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
WebDriver+Browser: Implement GET /session/{id}/element/{id}/screenshot
This commit is contained in:
parent
3c1c2994f1
commit
b0eb45f7c7
9 changed files with 79 additions and 0 deletions
|
@ -607,6 +607,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
|||
return active_tab().view().query_selector_all(start_node_id, selector);
|
||||
};
|
||||
|
||||
new_tab.webdriver_endpoints().on_scroll_element_into_view = [this](i32 element_id) {
|
||||
active_tab().view().scroll_element_into_view(element_id);
|
||||
};
|
||||
|
||||
new_tab.webdriver_endpoints().on_is_element_selected = [this](i32 element_id) {
|
||||
return active_tab().view().is_element_selected(element_id);
|
||||
};
|
||||
|
@ -651,6 +655,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
|||
return active_tab().view().webdriver_execute_script(body, json_arguments, timeout, async);
|
||||
};
|
||||
|
||||
new_tab.webdriver_endpoints().on_take_element_screenshot = [this](i32 element_id) {
|
||||
return active_tab().view().take_element_screenshot(element_id);
|
||||
};
|
||||
|
||||
new_tab.load(url);
|
||||
|
||||
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);
|
||||
|
|
|
@ -218,6 +218,16 @@ Messages::WebDriverSessionClient::QuerySelectorAllResponse WebDriverConnection::
|
|||
return { {} };
|
||||
}
|
||||
|
||||
void WebDriverConnection::scroll_element_into_view(i32 element_id)
|
||||
{
|
||||
dbgln("WebDriverConnection: scroll_element_into_view {}", element_id);
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
auto& tab = browser_window->active_tab();
|
||||
if (tab.webdriver_endpoints().on_scroll_element_into_view)
|
||||
tab.webdriver_endpoints().on_scroll_element_into_view(element_id);
|
||||
}
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::IsElementSelectedResponse WebDriverConnection::is_element_selected(i32 element_id)
|
||||
{
|
||||
dbgln("WebDriverConnection: is_element_selected {}", element_id);
|
||||
|
@ -329,4 +339,16 @@ Messages::WebDriverSessionClient::TakeScreenshotResponse WebDriverConnection::ta
|
|||
return { {} };
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::TakeElementScreenshotResponse WebDriverConnection::take_element_screenshot(i32 element_id)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: take_element_screenshot {}", element_id);
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
auto& tab = browser_window->active_tab();
|
||||
if (tab.webdriver_endpoints().on_take_element_screenshot)
|
||||
return { tab.webdriver_endpoints().on_take_element_screenshot(element_id) };
|
||||
}
|
||||
|
||||
return { {} };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
||||
virtual Messages::WebDriverSessionClient::GetDocumentElementResponse get_document_element() override;
|
||||
virtual Messages::WebDriverSessionClient::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override;
|
||||
virtual void scroll_element_into_view(i32 element_id) override;
|
||||
virtual Messages::WebDriverSessionClient::IsElementSelectedResponse is_element_selected(i32 element_id) override;
|
||||
virtual Messages::WebDriverSessionClient::GetElementAttributeResponse get_element_attribute(i32 element_id, String const& name) override;
|
||||
virtual Messages::WebDriverSessionClient::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override;
|
||||
|
@ -68,6 +69,7 @@ public:
|
|||
virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override;
|
||||
virtual Messages::WebDriverSessionClient::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
|
||||
virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override;
|
||||
virtual Messages::WebDriverSessionClient::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
|
||||
|
||||
private:
|
||||
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
|
||||
Function<Optional<i32>()> on_get_document_element;
|
||||
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
||||
Function<void(i32 element_id)> on_scroll_element_into_view;
|
||||
Function<bool(i32 element_id)> on_is_element_selected;
|
||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute;
|
||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
|
||||
|
@ -34,6 +35,7 @@ public:
|
|||
Function<String(i32 element_id)> on_get_element_tag_name;
|
||||
Function<Gfx::IntRect(i32 element_id)> on_get_element_rect;
|
||||
Function<bool(i32 element_id)> on_is_element_enabled;
|
||||
Function<Gfx::ShareableBitmap(i32 element_id)> on_take_element_screenshot;
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -31,6 +31,7 @@ endpoint WebDriverSessionClient {
|
|||
update_cookie(Web::Cookie::Cookie cookie) =|
|
||||
get_document_element() => (Optional<i32> document_element_id)
|
||||
query_selector_all(i32 start_node_id, String selector) => (Optional<Vector<i32>> elements_ids)
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
is_element_selected(i32 element_id) => (bool selected)
|
||||
get_element_attribute(i32 element_id, String name) => (Optional<String> atttibute)
|
||||
get_element_property(i32 element_id, String name) => (Optional<String> property)
|
||||
|
@ -41,4 +42,5 @@ endpoint WebDriverSessionClient {
|
|||
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
||||
is_element_enabled(i32 element_id) => (bool enabled)
|
||||
take_screenshot() => (Gfx::ShareableBitmap data)
|
||||
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue