1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

WebDriver+Browser: Implement GET /session/{id}/element/{id}/screenshot

This commit is contained in:
Timothy Flynn 2022-11-04 20:28:42 -04:00 committed by Linus Groh
parent 3c1c2994f1
commit b0eb45f7c7
9 changed files with 79 additions and 0 deletions

View file

@ -62,6 +62,7 @@ Vector<Client::Route> Client::s_routes = {
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie", ":name" }, &Client::handle_delete_cookie },
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie" }, &Client::handle_delete_all_cookies },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "screenshot" }, &Client::handle_take_screenshot },
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "screenshot" }, &Client::handle_take_element_screenshot },
};
Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
@ -812,4 +813,14 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_take_screenshot(Vector<StringV
return make_json_value(result);
}
// 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot
// GET /session/{session id}/element/{element id}/screenshot
ErrorOr<JsonValue, WebDriverError> Client::handle_take_element_screenshot(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/screenshot");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->take_element_screenshot(parameters[1]));
return make_json_value(result);
}
}