mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:17:45 +00:00
WebDriver: Implement GET /session/{session id}/timeouts
endpoint
This commit is contained in:
parent
4db5f6d081
commit
5c32eacac9
7 changed files with 68 additions and 2 deletions
|
@ -7,6 +7,7 @@ set(SOURCES
|
|||
BrowserConnection.cpp
|
||||
Client.cpp
|
||||
Session.cpp
|
||||
TimeoutsConfiguration.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Client.h"
|
||||
#include "Session.h"
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/JsonParser.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/MemoryStream.h>
|
||||
#include <LibHTTP/HttpRequest.h>
|
||||
#include <LibHTTP/HttpResponse.h>
|
||||
#include <WebDriver/Client.h>
|
||||
#include <WebDriver/Session.h>
|
||||
#include <WebDriver/TimeoutsConfiguration.h>
|
||||
|
||||
namespace WebDriver {
|
||||
|
||||
|
@ -24,6 +25,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::POST, { "session" }, &Client::handle_new_session },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id" }, &Client::handle_delete_session },
|
||||
{ HTTP::HttpRequest::Method::GET, { "status" }, &Client::handle_get_status },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "timeouts" }, &Client::handle_get_timeouts },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "url" }, &Client::handle_navigate_to },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_current_url },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "back" }, &Client::handle_back },
|
||||
|
@ -426,6 +428,18 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_status(Vector<StringView> const
|
|||
return body;
|
||||
}
|
||||
|
||||
// 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts
|
||||
// GET /session/{session id}/timeouts
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_get_timeouts(Vector<AK::StringView> const& parameters, AK::JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session id>/timeouts");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::get_timeouts().
|
||||
auto result = session->get_timeouts();
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
|
||||
// POST /session/{session id}/url
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -49,6 +50,7 @@ private:
|
|||
ErrorOr<JsonValue, HttpError> handle_new_session(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_session(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_status(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_timeouts(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_back(Vector<StringView> const&, JsonValue const& payload);
|
||||
|
|
|
@ -73,6 +73,16 @@ ErrorOr<void> Session::stop()
|
|||
return {};
|
||||
}
|
||||
|
||||
// 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts
|
||||
JsonObject Session::get_timeouts()
|
||||
{
|
||||
// 1. Let timeouts be the timeouts object for session’s timeouts configuration
|
||||
auto timeouts = timeouts_object(m_timeouts_configuration);
|
||||
|
||||
// 2. Return success with data timeouts.
|
||||
return timeouts;
|
||||
}
|
||||
|
||||
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
|
||||
ErrorOr<JsonValue, HttpError> Session::navigate_to(JsonValue const& payload)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
ErrorOr<void> start();
|
||||
ErrorOr<void> stop();
|
||||
JsonObject get_timeouts();
|
||||
ErrorOr<JsonValue, HttpError> navigate_to(JsonValue const& url);
|
||||
ErrorOr<JsonValue, HttpError> get_current_url();
|
||||
ErrorOr<JsonValue, HttpError> back();
|
||||
|
|
36
Userland/Services/WebDriver/TimeoutsConfiguration.cpp
Normal file
36
Userland/Services/WebDriver/TimeoutsConfiguration.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <WebDriver/TimeoutsConfiguration.h>
|
||||
|
||||
namespace WebDriver {
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-timeouts-object
|
||||
JsonObject timeouts_object(TimeoutsConfiguration const& timeouts)
|
||||
{
|
||||
// The timeouts object for a timeouts configuration timeouts is an object initialized with the following properties:
|
||||
auto timeouts_object = JsonObject {};
|
||||
|
||||
// "script"
|
||||
// timeouts' script timeout value, if set, or its default value.
|
||||
if (timeouts.script_timeout.has_value())
|
||||
timeouts_object.set("script", *timeouts.script_timeout);
|
||||
else
|
||||
timeouts_object.set("script", JsonValue {});
|
||||
|
||||
// "pageLoad"
|
||||
// timeouts' page load timeout’s value, if set, or its default value.
|
||||
timeouts_object.set("pageLoad", timeouts.page_load_timeout);
|
||||
|
||||
// "implicit"
|
||||
// timeouts' implicit wait timeout’s value, if set, or its default value.
|
||||
timeouts_object.set("implicit", timeouts.implicit_wait_timeout);
|
||||
|
||||
return timeouts_object;
|
||||
}
|
||||
|
||||
}
|
|
@ -18,4 +18,6 @@ struct TimeoutsConfiguration {
|
|||
u64 implicit_wait_timeout { 0 };
|
||||
};
|
||||
|
||||
JsonObject timeouts_object(TimeoutsConfiguration const&);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue