WebDriver: Implement GET /session/{id}/url endpoint

This commit is contained in:
Sam Atkins 2022-10-10 11:45:21 +01:00 committed by Linus Groh
parent a15d32982a
commit 096fe865c6
Notes: sideshowbarker 2024-07-17 06:00:14 +09:00
3 changed files with 23 additions and 3 deletions

View file

@ -417,12 +417,14 @@ ErrorOr<JsonValue, HttpError> Client::handle_post_url(Vector<StringView> paramet
}
// GET /session/{session id}/url https://w3c.github.io/webdriver/#dfn-get-current-url
ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView>, JsonValue const&)
ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView> parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url");
Session* session = TRY(find_session_with_id(parameters[0]));
// FIXME: Implement the spec steps
return HttpError { 400, "", "" };
// NOTE: Spec steps handled in Session::get_url().
auto result = TRY(session->get_url());
return make_json_value(result);
}
// GET /session/{session id}/title https://w3c.github.io/webdriver/#dfn-get-title

View file

@ -126,6 +126,23 @@ ErrorOr<JsonValue, HttpError> Session::post_url(JsonValue const& payload)
return JsonValue();
}
// GET /session/{session id}/url https://w3c.github.io/webdriver/#dfn-get-current-url
ErrorOr<JsonValue, HttpError> Session::get_url()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = get_window_object();
if (!current_window.has_value())
return HttpError { 400, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
// 3. Let url be the serialization of the current top-level browsing contexts active documents document URL.
auto url = m_browser_connection->get_url().to_string();
// 4. Return success with data url.
return JsonValue(url);
}
// GET /session/{session id}/title https://w3c.github.io/webdriver/#dfn-get-title
ErrorOr<JsonValue, HttpError> Session::get_title()
{

View file

@ -35,6 +35,7 @@ public:
ErrorOr<void> stop();
ErrorOr<void, Variant<HttpError, Error>> delete_window();
ErrorOr<JsonValue, HttpError> post_url(JsonValue const& url);
ErrorOr<JsonValue, HttpError> get_url();
ErrorOr<JsonValue, HttpError> get_title();
private: