mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
WebDriver+Browser: Implement GET /session/{id}/source
This commit is contained in:
parent
82af1557dd
commit
61d0b66bfb
9 changed files with 49 additions and 0 deletions
|
@ -49,6 +49,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "css", ":property_name" }, &Client::handle_get_element_css_value },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "text" }, &Client::handle_get_element_text },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "name" }, &Client::handle_get_element_tag_name },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "source" }, &Client::handle_get_source },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "execute", "sync" }, &Client::handle_execute_script },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "execute", "async" }, &Client::handle_execute_async_script },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie" }, &Client::handle_get_all_cookies },
|
||||
|
@ -687,6 +688,16 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_tag_name(Vector<St
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
|
||||
// GET /session/{session id}/source
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_get_source(Vector<StringView> const& parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/source");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->get_source());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script
|
||||
// POST /session/{session id}/execute/sync
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_execute_script(Vector<StringView> const& parameters, JsonValue const& payload)
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
ErrorOr<JsonValue, WebDriverError> handle_get_element_css_value(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_element_text(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_element_tag_name(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_source(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_execute_script(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_execute_async_script(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_all_cookies(Vector<StringView> const&, JsonValue const& payload);
|
||||
|
|
|
@ -900,6 +900,23 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_tag_name(JsonValue const
|
|||
return JsonValue(qualified_name);
|
||||
}
|
||||
|
||||
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
|
||||
ErrorOr<JsonValue, WebDriverError> Session::get_source()
|
||||
{
|
||||
// 1. If the current 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. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only child is the document element providing true for the require well-formed flag. If this causes an exception to be thrown, let source be null.
|
||||
// 4. Let source be the result of serializing to string the current browsing context active document, if source is null.
|
||||
// NOTE: Both of the above cases are handled in the remote WebContent process.
|
||||
auto source = m_browser_connection->serialize_source();
|
||||
|
||||
// 5. Return success with data source.
|
||||
return source;
|
||||
}
|
||||
|
||||
struct ScriptArguments {
|
||||
String script;
|
||||
JsonArray const& arguments;
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
ErrorOr<JsonValue, WebDriverError> get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
|
||||
ErrorOr<JsonValue, WebDriverError> get_element_text(JsonValue const& payload, StringView element_id);
|
||||
ErrorOr<JsonValue, WebDriverError> get_element_tag_name(JsonValue const& payload, StringView element_id);
|
||||
ErrorOr<JsonValue, WebDriverError> get_source();
|
||||
ErrorOr<JsonValue, WebDriverError> execute_script(JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> execute_async_script(JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> get_all_cookies();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue