summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Error.cpp (renamed from Userland/Services/WebDriver/WebDriverError.cpp)6
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Error.h (renamed from Userland/Services/WebDriver/WebDriverError.h)10
-rw-r--r--Userland/Services/WebDriver/CMakeLists.txt5
-rw-r--r--Userland/Services/WebDriver/Client.cpp100
-rw-r--r--Userland/Services/WebDriver/Client.h112
-rw-r--r--Userland/Services/WebDriver/Session.cpp228
-rw-r--r--Userland/Services/WebDriver/Session.h92
-rw-r--r--Userland/Services/WebDriver/TimeoutsConfiguration.cpp11
-rw-r--r--Userland/Services/WebDriver/TimeoutsConfiguration.h4
10 files changed, 284 insertions, 285 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 55a91a57dd..da87a6c0db 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -438,6 +438,7 @@ set(SOURCES
WebAssembly/WebAssemblyTableConstructor.cpp
WebAssembly/WebAssemblyTableObject.cpp
WebAssembly/WebAssemblyTablePrototype.cpp
+ WebDriver/Error.cpp
WebDriver/ExecuteScript.cpp
WebGL/WebGLContextAttributes.cpp
WebGL/WebGLContextEvent.cpp
diff --git a/Userland/Services/WebDriver/WebDriverError.cpp b/Userland/Libraries/LibWeb/WebDriver/Error.cpp
index 8d51e10700..2fdc3e6487 100644
--- a/Userland/Services/WebDriver/WebDriverError.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/Error.cpp
@@ -4,10 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "WebDriverError.h"
#include <AK/Vector.h>
+#include <LibWeb/WebDriver/Error.h>
-namespace WebDriver {
+namespace Web::WebDriver {
struct ErrorCodeData {
ErrorCode error_code;
@@ -47,7 +47,7 @@ static Vector<ErrorCodeData> const s_error_code_data = {
{ ErrorCode::UnsupportedOperation, 500, "unsupported operation" },
};
-WebDriverError WebDriverError::from_code(ErrorCode code, String message, Optional<JsonValue> data)
+Error Error::from_code(ErrorCode code, String message, Optional<JsonValue> data)
{
auto const& error_code_data = s_error_code_data[to_underlying(code)];
return {
diff --git a/Userland/Services/WebDriver/WebDriverError.h b/Userland/Libraries/LibWeb/WebDriver/Error.h
index bd05d6fa80..4bb2c3aa1c 100644
--- a/Userland/Services/WebDriver/WebDriverError.h
+++ b/Userland/Libraries/LibWeb/WebDriver/Error.h
@@ -10,7 +10,7 @@
#include <AK/JsonValue.h>
#include <AK/String.h>
-namespace WebDriver {
+namespace Web::WebDriver {
// https://w3c.github.io/webdriver/#dfn-error-code
enum class ErrorCode {
@@ -45,20 +45,20 @@ enum class ErrorCode {
};
// https://w3c.github.io/webdriver/#errors
-struct WebDriverError {
+struct Error {
unsigned http_status;
String error;
String message;
Optional<JsonValue> data;
- static WebDriverError from_code(ErrorCode, String message, Optional<JsonValue> data = {});
+ static Error from_code(ErrorCode, String message, Optional<JsonValue> data = {});
};
}
template<>
-struct AK::Formatter<WebDriver::WebDriverError> : Formatter<StringView> {
- ErrorOr<void> format(FormatBuilder& builder, WebDriver::WebDriverError const& error)
+struct AK::Formatter<Web::WebDriver::Error> : Formatter<StringView> {
+ ErrorOr<void> format(FormatBuilder& builder, Web::WebDriver::Error const& error)
{
return Formatter<StringView>::format(builder, String::formatted("Error {}, {}: {}", error.http_status, error.error, error.message));
}
diff --git a/Userland/Services/WebDriver/CMakeLists.txt b/Userland/Services/WebDriver/CMakeLists.txt
index de733a88e5..61bda04597 100644
--- a/Userland/Services/WebDriver/CMakeLists.txt
+++ b/Userland/Services/WebDriver/CMakeLists.txt
@@ -8,14 +8,13 @@ set(SOURCES
Client.cpp
Session.cpp
TimeoutsConfiguration.cpp
- WebDriverError.cpp
main.cpp
- )
+)
set(GENERATED_SOURCES
../../Applications/Browser/WebDriverSessionClientEndpoint.h
../../Applications/Browser/WebDriverSessionServerEndpoint.h
- )
+)
serenity_bin(WebDriver)
target_link_libraries(WebDriver PRIVATE LibCore LibHTTP LibMain LibIPC LibWeb LibGfx)
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp
index 021adf4c7c..a318f32b60 100644
--- a/Userland/Services/WebDriver/Client.cpp
+++ b/Userland/Services/WebDriver/Client.cpp
@@ -226,7 +226,7 @@ ErrorOr<void> Client::send_response(StringView content, HTTP::HttpRequest const&
}
// https://w3c.github.io/webdriver/#dfn-send-an-error
-ErrorOr<void> Client::send_error_response(WebDriverError const& error, HTTP::HttpRequest const& request)
+ErrorOr<void> Client::send_error_response(Web::WebDriver::Error const& error, HTTP::HttpRequest const& request)
{
// FIXME: Implement to spec.
@@ -263,7 +263,7 @@ void Client::log_response(unsigned code, HTTP::HttpRequest const& request)
}
// https://w3c.github.io/webdriver/#dfn-match-a-request
-ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpRequest::Method method, String const& resource)
+ErrorOr<Client::RoutingResult, Web::WebDriver::Error> Client::match_route(HTTP::HttpRequest::Method method, String const& resource)
{
// FIXME: Implement to spec.
@@ -271,7 +271,7 @@ ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpReq
// https://w3c.github.io/webdriver/webdriver-spec.html#routing-requests
if (!resource.starts_with(m_prefix))
- return WebDriverError::from_code(ErrorCode::UnknownCommand, "The resource doesn't start with the prefix.");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnknownCommand, "The resource doesn't start with the prefix.");
Vector<StringView> resource_split = resource.substring_view(m_prefix.length()).split_view('/', SplitBehavior::KeepEmpty);
Vector<StringView> parameters;
@@ -310,25 +310,25 @@ ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpReq
// Matched a path, but didn't match a known method
if (matched_path) {
dbgln_if(WEBDRIVER_DEBUG, "- A path matched, but method didn't. :^(");
- return WebDriverError::from_code(ErrorCode::UnknownMethod, "The command matched a known URL but did not match a method for that URL.");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnknownMethod, "The command matched a known URL but did not match a method for that URL.");
}
// Didn't have any match
dbgln_if(WEBDRIVER_DEBUG, "- No matches. :^(");
- return WebDriverError::from_code(ErrorCode::UnknownCommand, "The command was not recognized.");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnknownCommand, "The command was not recognized.");
}
-ErrorOr<Session*, WebDriverError> Client::find_session_with_id(StringView session_id)
+ErrorOr<Session*, Web::WebDriver::Error> Client::find_session_with_id(StringView session_id)
{
auto session_id_or_error = session_id.to_uint<>();
if (!session_id_or_error.has_value())
- return WebDriverError::from_code(ErrorCode::InvalidSessionId, "Invalid session id");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
for (auto& session : Client::s_sessions) {
if (session.session_id() == session_id_or_error.value())
return &session;
}
- return WebDriverError::from_code(ErrorCode::InvalidSessionId, "Invalid session id");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
}
void Client::close_session(unsigned session_id)
@@ -352,7 +352,7 @@ JsonValue Client::make_json_value(JsonValue const& value)
// 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions
// POST /session
-ErrorOr<JsonValue, WebDriverError> Client::handle_new_session(Vector<StringView> const&, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_new_session(Vector<StringView> const&, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session");
@@ -382,7 +382,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_new_session(Vector<StringView>
NonnullOwnPtr<Session> session = make<Session>(session_id, *this);
auto start_result = session->start();
if (start_result.is_error()) {
- return WebDriverError::from_code(ErrorCode::SessionNotCreated, String::formatted("Failed to start session: {}", start_result.error().string_literal()));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::SessionNotCreated, String::formatted("Failed to start session: {}", start_result.error().string_literal()));
}
// FIXME: 8. Set the current session to session.
@@ -418,7 +418,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_new_session(Vector<StringView>
// 8.2 Delete Session, https://w3c.github.io/webdriver/#dfn-delete-session
// DELETE /session/{session id}
-ErrorOr<JsonValue, WebDriverError> Client::handle_delete_session(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_delete_session(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>");
@@ -427,7 +427,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_session(Vector<StringVi
auto stop_result = session->stop();
if (stop_result.is_error())
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, stop_result.error().string_literal());
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, stop_result.error().string_literal());
// 2. Return success with data null.
return make_json_value(JsonValue());
@@ -435,7 +435,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_session(Vector<StringVi
// 8.3 Status, https://w3c.github.io/webdriver/#dfn-status
// GET /status
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_status(Vector<StringView> const&, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_status(Vector<StringView> const&, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /status");
@@ -455,7 +455,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_status(Vector<StringView>
// 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts
// GET /session/{session id}/timeouts
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_timeouts(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_timeouts(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session id>/timeouts");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -465,7 +465,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_timeouts(Vector<StringView
// 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts
// POST /session/{session id}/timeouts
-ErrorOr<JsonValue, WebDriverError> Client::handle_set_timeouts(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_set_timeouts(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session id>/timeouts");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -475,7 +475,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_set_timeouts(Vector<StringView
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
// POST /session/{session id}/url
-ErrorOr<JsonValue, WebDriverError> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/url");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -485,7 +485,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_navigate_to(Vector<StringView>
// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
// GET /session/{session id}/url
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_current_url(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_current_url(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -495,7 +495,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_current_url(Vector<StringV
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
// POST /session/{session id}/back
-ErrorOr<JsonValue, WebDriverError> Client::handle_back(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_back(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/back");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -505,7 +505,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_back(Vector<StringView> const&
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
// POST /session/{session id}/forward
-ErrorOr<JsonValue, WebDriverError> Client::handle_forward(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_forward(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/forward");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -515,7 +515,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_forward(Vector<StringView> con
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
// POST /session/{session id}/refresh
-ErrorOr<JsonValue, WebDriverError> Client::handle_refresh(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_refresh(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/refresh");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -525,7 +525,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_refresh(Vector<StringView> con
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
// GET /session/{session id}/title
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_title(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_title(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/title");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -535,7 +535,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_title(Vector<StringView> c
// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
// GET /session/{session id}/window
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handle(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_window_handle(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -545,7 +545,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handle(Vector<Strin
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
// DELETE /session/{session id}/window
-ErrorOr<JsonValue, WebDriverError> Client::handle_close_window(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_close_window(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -555,7 +555,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_close_window(Vector<StringView
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
// GET /session/{session id}/window/handles
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handles(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_window_handles(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window/handles");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -565,7 +565,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handles(Vector<Stri
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect
// GET /session/{session id}/window/rect
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_rect(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_window_rect(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window/rect");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -575,7 +575,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_rect(Vector<StringV
// 11.8.2 Set Window Rect, https://w3c.github.io/webdriver/#dfn-set-window-rect
// POST /session/{session id}/window/rect
-ErrorOr<JsonValue, WebDriverError> Client::handle_set_window_rect(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_set_window_rect(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/rect");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -585,7 +585,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_set_window_rect(Vector<StringV
// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window
// POST /session/{session id}/window/maximize
-ErrorOr<JsonValue, WebDriverError> Client::handle_maximize_window(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_maximize_window(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/maximize");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -595,7 +595,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_maximize_window(Vector<StringV
// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
// POST /session/{session id}/window/minimize
-ErrorOr<JsonValue, WebDriverError> Client::handle_minimize_window(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_minimize_window(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/minimize");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -605,7 +605,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_minimize_window(Vector<StringV
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
// POST /session/{session id}/element
-ErrorOr<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -615,7 +615,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView
// 12.3.3 Find Elements, https://w3c.github.io/webdriver/#dfn-find-elements
// POST /session/{session id}/elements
-ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_find_elements(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/elements");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -625,7 +625,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements(Vector<StringVie
// 12.3.4 Find Element From Element, https://w3c.github.io/webdriver/#dfn-find-element-from-element
// POST /session/{session id}/element/{element id}/element
-ErrorOr<JsonValue, WebDriverError> Client::handle_find_element_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_find_element_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element/<element_id>/element");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -635,7 +635,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_find_element_from_element(Vect
// 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element
// POST /session/{session id}/element/{element id}/elements
-ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_find_elements_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element/<element_id>/elements");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -645,7 +645,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements_from_element(Vec
// 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected
// GET /session/{session id}/element/{element id}/selected
-ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/selected");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -655,7 +655,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_selected(Vector<Str
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
// GET /session/{session id}/element/{element id}/attribute/{name}
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_attribute(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_attribute(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/attribute/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -665,7 +665,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_attribute(Vector<S
// 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property
// GET /session/{session id}/element/{element id}/property/{name}
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_property(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_property(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/property/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -675,7 +675,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_property(Vector<St
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
// GET /session/{session id}/element/{element id}/css/{property name}
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/css/<property_name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -685,7 +685,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_css_value(Vector<S
// 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text
// GET /session/{session id}/element/{element id}/text
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_text(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_text(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/text");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -695,7 +695,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_text(Vector<String
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
// GET /session/{session id}/element/{element id}/name
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_tag_name(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_tag_name(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/name");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -705,7 +705,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_tag_name(Vector<St
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
// GET /session/{session id}/element/{element id}/rect
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_rect(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_element_rect(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/rect");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -715,7 +715,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_rect(Vector<String
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
// GET /session/{session id}/element/{element id}/enabled
-ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_enabled(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_is_element_enabled(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/enabled");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -725,7 +725,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_enabled(Vector<Stri
// 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&)
+ErrorOr<JsonValue, Web::WebDriver::Error> 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]));
@@ -735,7 +735,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_source(Vector<StringView>
// 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)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_execute_script(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/execute/sync");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -745,7 +745,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_execute_script(Vector<StringVi
// 13.2.2 Execute Async Script, https://w3c.github.io/webdriver/#dfn-execute-async-script
// POST /session/{session id}/execute/async
-ErrorOr<JsonValue, WebDriverError> Client::handle_execute_async_script(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_execute_async_script(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/execute/async");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -755,7 +755,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_execute_async_script(Vector<St
// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies
// GET /session/{session id}/cookie
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -765,7 +765,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_all_cookies(Vector<StringV
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
// GET /session/{session id}/cookie/{name}
-ErrorOr<JsonValue, WebDriverError> Client::handle_get_named_cookie(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_get_named_cookie(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/cookie/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -775,7 +775,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_get_named_cookie(Vector<String
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
// POST /session/{session id}/cookie
-ErrorOr<JsonValue, WebDriverError> Client::handle_add_cookie(Vector<StringView> const& parameters, JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_add_cookie(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -785,7 +785,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_add_cookie(Vector<StringView>
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
// DELETE /session/{session id}/cookie/{name}
-ErrorOr<JsonValue, WebDriverError> Client::handle_delete_cookie(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_delete_cookie(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -795,7 +795,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_cookie(Vector<StringVie
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
// DELETE /session/{session id}/cookie
-ErrorOr<JsonValue, WebDriverError> Client::handle_delete_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_delete_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -805,7 +805,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_all_cookies(Vector<Stri
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
// GET /session/{session id}/screenshot
-ErrorOr<JsonValue, WebDriverError> Client::handle_take_screenshot(Vector<StringView> const& parameters, JsonValue const&)
+ErrorOr<JsonValue, Web::WebDriver::Error> Client::handle_take_screenshot(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/screenshot");
auto* session = TRY(find_session_with_id(parameters[0]));
@@ -815,7 +815,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_take_screenshot(Vector<StringV
// 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&)
+ErrorOr<JsonValue, Web::WebDriver::Error> 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]));
diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h
index 65820de97e..b9a9eeed7a 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -13,8 +13,8 @@
#include <LibCore/Stream.h>
#include <LibHTTP/Forward.h>
#include <LibHTTP/HttpRequest.h>
+#include <LibWeb/WebDriver/Error.h>
#include <WebDriver/Session.h>
-#include <WebDriver/WebDriverError.h>
namespace WebDriver {
@@ -31,11 +31,11 @@ private:
ErrorOr<JsonValue> read_body_as_json(HTTP::HttpRequest const&);
ErrorOr<bool> handle_request(HTTP::HttpRequest const&, JsonValue const& body);
ErrorOr<void> send_response(StringView content, HTTP::HttpRequest const&);
- ErrorOr<void> send_error_response(WebDriverError const& error, HTTP::HttpRequest const&);
+ ErrorOr<void> send_error_response(Web::WebDriver::Error const& error, HTTP::HttpRequest const&);
void die();
void log_response(unsigned code, HTTP::HttpRequest const&);
- using RouteHandler = ErrorOr<JsonValue, WebDriverError> (Client::*)(Vector<StringView> const&, JsonValue const&);
+ using RouteHandler = ErrorOr<JsonValue, Web::WebDriver::Error> (Client::*)(Vector<StringView> const&, JsonValue const&);
struct Route {
HTTP::HttpRequest::Method method;
Vector<String> path;
@@ -47,70 +47,70 @@ private:
Vector<StringView> parameters;
};
- ErrorOr<RoutingResult, WebDriverError> match_route(HTTP::HttpRequest::Method method, String const& resource);
- ErrorOr<JsonValue, WebDriverError> handle_new_session(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_delete_session(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_status(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_timeouts(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_set_timeouts(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_back(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_forward(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_refresh(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_title(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_close_window(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_window_handles(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_window_rect(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_set_window_rect(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_maximize_window(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_minimize_window(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_find_element(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_find_elements_from_element(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_element_attribute(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_get_element_property(Vector<StringView> const&, JsonValue const& payload);
- 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_element_rect(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_is_element_enabled(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);
- ErrorOr<JsonValue, WebDriverError> handle_get_named_cookie(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_add_cookie(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_delete_cookie(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_delete_all_cookies(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_take_screenshot(Vector<StringView> const&, JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> handle_take_element_screenshot(Vector<StringView> const&, JsonValue const& payload);
-
- ErrorOr<Session*, WebDriverError> find_session_with_id(StringView session_id);
+ ErrorOr<RoutingResult, Web::WebDriver::Error> match_route(HTTP::HttpRequest::Method method, String const& resource);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_new_session(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_delete_session(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_status(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_timeouts(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_set_timeouts(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_back(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_forward(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_refresh(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_title(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_close_window(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_window_handles(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_window_rect(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_set_window_rect(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_maximize_window(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_minimize_window(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_find_element(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_find_elements_from_element(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_attribute(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_property(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_css_value(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_text(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_tag_name(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_element_rect(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_is_element_enabled(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_source(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_execute_script(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_execute_async_script(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_all_cookies(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_get_named_cookie(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_add_cookie(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_delete_cookie(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_delete_all_cookies(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_take_screenshot(Vector<StringView> const&, JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> handle_take_element_screenshot(Vector<StringView> const&, JsonValue const& payload);
+
+ ErrorOr<Session*, Web::WebDriver::Error> find_session_with_id(StringView session_id);
JsonValue make_json_value(JsonValue const&);
template<typename T>
- static ErrorOr<T, WebDriverError> unwrap_result(ErrorOr<T, Variant<WebDriverError, Error>> result)
+ static ErrorOr<T, Web::WebDriver::Error> unwrap_result(ErrorOr<T, Variant<Web::WebDriver::Error, Error>> result)
{
if (result.is_error()) {
- Variant<WebDriverError, Error> error = result.release_error();
- if (error.has<WebDriverError>())
- return error.get<WebDriverError>();
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
+ Variant<Web::WebDriver::Error, Error> error = result.release_error();
+ if (error.has<Web::WebDriver::Error>())
+ return error.get<Web::WebDriver::Error>();
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
}
return result.release_value();
}
- static ErrorOr<void, WebDriverError> unwrap_result(ErrorOr<void, Variant<WebDriverError, Error>> result)
+ static ErrorOr<void, Web::WebDriver::Error> unwrap_result(ErrorOr<void, Variant<Web::WebDriver::Error, Error>> result)
{
if (result.is_error()) {
- Variant<WebDriverError, Error> error = result.release_error();
- if (error.has<WebDriverError>())
- return error.get<WebDriverError>();
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
+ Variant<Web::WebDriver::Error, Error> error = result.release_error();
+ if (error.has<Web::WebDriver::Error>())
+ return error.get<Web::WebDriver::Error>();
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
}
return {};
}
diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp
index 179a7c134f..d494eeb323 100644
--- a/Userland/Services/WebDriver/Session.cpp
+++ b/Userland/Services/WebDriver/Session.cpp
@@ -45,15 +45,15 @@ Session::~Session()
}
}
-ErrorOr<Session::Window*, WebDriverError> Session::current_window()
+ErrorOr<Session::Window*, Web::WebDriver::Error> Session::current_window()
{
auto window = m_windows.get(m_current_window_handle);
if (!window.has_value())
- return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");
return window.release_value();
}
-ErrorOr<void, WebDriverError> Session::check_for_open_top_level_browsing_context_or_return_error()
+ErrorOr<void, Web::WebDriver::Error> Session::check_for_open_top_level_browsing_context_or_return_error()
{
(void)TRY(current_window());
return {};
@@ -107,7 +107,7 @@ JsonObject Session::get_timeouts()
}
// 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts
-ErrorOr<JsonValue, WebDriverError> Session::set_timeouts(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::set_timeouts(JsonValue const& payload)
{
// 1. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the requestā€™s parameters.
auto timeouts = TRY(json_deserialize_as_a_timeouts_configuration(payload));
@@ -120,7 +120,7 @@ ErrorOr<JsonValue, WebDriverError> Session::set_timeouts(JsonValue const& payloa
}
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
-ErrorOr<JsonValue, WebDriverError> Session::navigate_to(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::navigate_to(JsonValue const& payload)
{
// 1. If the current top-level 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());
@@ -129,7 +129,7 @@ ErrorOr<JsonValue, WebDriverError> Session::navigate_to(JsonValue const& payload
// 3. If the url property is missing from the parameters argument or it is not a string, return error with error code invalid argument.
if (!payload.is_object() || !payload.as_object().has_string("url"sv)) {
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload doesn't have a string url");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have a string url");
}
// 4. Let url be the result of getting a property named url from the parameters argument.
@@ -154,7 +154,7 @@ ErrorOr<JsonValue, WebDriverError> Session::navigate_to(JsonValue const& payload
}
// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
-ErrorOr<JsonValue, WebDriverError> Session::get_current_url()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_current_url()
{
// 1. If the current top-level 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());
@@ -169,7 +169,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_current_url()
}
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
-ErrorOr<JsonValue, WebDriverError> Session::back()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::back()
{
// 1. If the current top-level 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());
@@ -190,7 +190,7 @@ ErrorOr<JsonValue, WebDriverError> Session::back()
}
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
-ErrorOr<JsonValue, WebDriverError> Session::forward()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::forward()
{
// 1. If the current top-level 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());
@@ -211,7 +211,7 @@ ErrorOr<JsonValue, WebDriverError> Session::forward()
}
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
-ErrorOr<JsonValue, WebDriverError> Session::refresh()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::refresh()
{
// 1. If the current top-level 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());
@@ -234,7 +234,7 @@ ErrorOr<JsonValue, WebDriverError> Session::refresh()
}
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
-ErrorOr<JsonValue, WebDriverError> Session::get_title()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_title()
{
// 1. If the current top-level 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());
@@ -247,7 +247,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_title()
}
// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
-ErrorOr<JsonValue, WebDriverError> Session::get_window_handle()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_window_handle()
{
// 1. If the current top-level 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());
@@ -257,7 +257,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_window_handle()
}
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
-ErrorOr<void, Variant<WebDriverError, Error>> Session::close_window()
+ErrorOr<void, Variant<Web::WebDriver::Error, Error>> Session::close_window()
{
// 1. If the current top-level 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());
@@ -269,7 +269,7 @@ ErrorOr<void, Variant<WebDriverError, Error>> Session::close_window()
if (m_windows.is_empty()) {
auto result = stop();
if (result.is_error()) {
- return Variant<WebDriverError, Error>(result.release_error());
+ return Variant<Web::WebDriver::Error, Error>(result.release_error());
}
}
@@ -277,7 +277,7 @@ ErrorOr<void, Variant<WebDriverError, Error>> Session::close_window()
}
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
-ErrorOr<JsonValue, WebDriverError> Session::get_window_handles() const
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_window_handles() const
{
// 1. Let handles be a JSON List.
auto handles = JsonArray {};
@@ -302,7 +302,7 @@ static JsonObject serialize_rect(Gfx::IntRect const& rect)
}
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect
-ErrorOr<JsonValue, WebDriverError> Session::get_window_rect()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_window_rect()
{
// 1. If the current top-level 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());
@@ -314,25 +314,25 @@ ErrorOr<JsonValue, WebDriverError> Session::get_window_rect()
}
// 11.8.2 Set Window Rect, https://w3c.github.io/webdriver/#dfn-set-window-rect
-ErrorOr<JsonValue, WebDriverError> Session::set_window_rect(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::set_window_rect(JsonValue const& payload)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
- auto resolve_property = [](auto name, auto const* property, auto min, auto max) -> ErrorOr<Optional<i32>, WebDriverError> {
+ auto resolve_property = [](auto name, auto const* property, auto min, auto max) -> ErrorOr<Optional<i32>, Web::WebDriver::Error> {
if (!property)
return Optional<i32> {};
if (!property->is_number())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, String::formatted("Property '{}' is not a Number", name));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, String::formatted("Property '{}' is not a Number", name));
auto number = property->template to_number<i64>();
if (number < min)
- return WebDriverError::from_code(ErrorCode::InvalidArgument, String::formatted("Property '{}' value {} exceeds the minimum allowed value {}", name, number, min));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, String::formatted("Property '{}' value {} exceeds the minimum allowed value {}", name, number, min));
if (number > max)
- return WebDriverError::from_code(ErrorCode::InvalidArgument, String::formatted("Property '{}' value {} exceeds the maximum allowed value {}", name, number, max));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, String::formatted("Property '{}' value {} exceeds the maximum allowed value {}", name, number, max));
return static_cast<i32>(number);
};
@@ -386,7 +386,7 @@ ErrorOr<JsonValue, WebDriverError> Session::set_window_rect(JsonValue const& pay
}
// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window
-ErrorOr<JsonValue, WebDriverError> Session::maximize_window()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::maximize_window()
{
// 1. If the remote end does not support the Maximize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
@@ -407,7 +407,7 @@ ErrorOr<JsonValue, WebDriverError> Session::maximize_window()
}
// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
-ErrorOr<JsonValue, WebDriverError> Session::minimize_window()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::minimize_window()
{
// 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
@@ -453,19 +453,19 @@ static JsonObject web_element_reference_object(Session::LocalElement const& elem
}
// https://w3c.github.io/webdriver/#dfn-get-a-known-connected-element
-static ErrorOr<i32, WebDriverError> get_known_connected_element(StringView element_id)
+static ErrorOr<i32, Web::WebDriver::Error> get_known_connected_element(StringView element_id)
{
// NOTE: The whole concept of "connected elements" is not implemented yet. See get_or_create_a_web_element_reference().
// For now the element is only represented by its ID.
auto maybe_element_id = element_id.to_int();
if (!maybe_element_id.has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an integer");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an integer");
return maybe_element_id.release_value();
}
// https://w3c.github.io/webdriver/#dfn-find
-ErrorOr<JsonArray, WebDriverError> Session::find(Session::LocalElement const& start_node, StringView using_, StringView value)
+ErrorOr<JsonArray, Web::WebDriver::Error> Session::find(Session::LocalElement const& start_node, StringView using_, StringView value)
{
// 1. Let end time be the current time plus the session implicit wait timeout.
auto end_time = Time::now_monotonic() + Time::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
@@ -479,13 +479,13 @@ ErrorOr<JsonArray, WebDriverError> Session::find(Session::LocalElement const& st
// 4. Let elements returned be the result of trying to call the relevant element location strategy with arguments start node, and selector.
auto location_strategy_handler = s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; });
if (!location_strategy_handler.has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No valid location strategy");
auto elements_or_error = (this->*location_strategy_handler.value().handler)(start_node, selector);
// 5. If a DOMException, SyntaxError, XPathException, or other error occurs during the execution of the element location strategy, return error invalid selector.
if (elements_or_error.is_error())
- return WebDriverError::from_code(ErrorCode::InvalidSelector, String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSelector, String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message));
auto elements = elements_or_error.release_value();
@@ -514,14 +514,14 @@ Vector<Session::LocatorStrategy> Session::s_locator_strategies = {
};
// https://w3c.github.io/webdriver/#css-selectors
-ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_css_selectors(Session::LocalElement const& start_node, StringView selector)
+ErrorOr<Vector<Session::LocalElement>, Web::WebDriver::Error> Session::locator_strategy_css_selectors(Session::LocalElement const& start_node, StringView selector)
{
// 1. Let elements be the result of calling querySelectorAll() with start node as this and selector as the argument.
// If this causes an exception to be thrown, return error with error code invalid selector.
auto elements_ids = m_browser_connection->query_selector_all(start_node.id, selector);
if (!elements_ids.has_value())
- return WebDriverError::from_code(ErrorCode::InvalidSelector, "query_selector_all returned failed!");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSelector, "query_selector_all returned failed!");
Vector<Session::LocalElement> elements;
for (auto id : elements_ids.release_value()) {
@@ -533,60 +533,60 @@ ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy
}
// https://w3c.github.io/webdriver/#link-text
-ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_link_text(Session::LocalElement const&, StringView)
+ErrorOr<Vector<Session::LocalElement>, Web::WebDriver::Error> Session::locator_strategy_link_text(Session::LocalElement const&, StringView)
{
// FIXME: Implement
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy link text");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, "Not implemented: locator strategy link text");
}
// https://w3c.github.io/webdriver/#partial-link-text
-ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_partial_link_text(Session::LocalElement const&, StringView)
+ErrorOr<Vector<Session::LocalElement>, Web::WebDriver::Error> Session::locator_strategy_partial_link_text(Session::LocalElement const&, StringView)
{
// FIXME: Implement
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy partial link text");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, "Not implemented: locator strategy partial link text");
}
// https://w3c.github.io/webdriver/#tag-name
-ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView)
+ErrorOr<Vector<Session::LocalElement>, Web::WebDriver::Error> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView)
{
// FIXME: Implement
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy tag name");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, "Not implemented: locator strategy tag name");
}
// https://w3c.github.io/webdriver/#xpath
-ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_x_path(Session::LocalElement const&, StringView)
+ErrorOr<Vector<Session::LocalElement>, Web::WebDriver::Error> Session::locator_strategy_x_path(Session::LocalElement const&, StringView)
{
// FIXME: Implement
- return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy XPath");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, "Not implemented: locator strategy XPath");
}
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
-ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::find_element(JsonValue const& payload)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string();
@@ -600,7 +600,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payloa
// 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value())
- return WebDriverError::from_code(ErrorCode::NoSuchElement, "document element does not exist");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "document element does not exist");
auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id };
@@ -610,38 +610,38 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payloa
// 10. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty())
- return WebDriverError::from_code(ErrorCode::NoSuchElement, "The requested element does not exist");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "The requested element does not exist");
return JsonValue(result.at(0));
}
// 12.3.3 Find Elements, https://w3c.github.io/webdriver/#dfn-find-elements
-ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::find_elements(JsonValue const& payload)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string();
@@ -655,7 +655,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& paylo
// 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value())
- return WebDriverError::from_code(ErrorCode::NoSuchElement, "document element does not exist");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "document element does not exist");
auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id };
@@ -666,32 +666,32 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& paylo
}
// 12.3.4 Find Element From Element, https://w3c.github.io/webdriver/#dfn-find-element-from-element
-ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string();
@@ -709,38 +709,38 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue
// 9. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty())
- return WebDriverError::from_code(ErrorCode::NoSuchElement, "The requested element does not exist");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "The requested element does not exist");
return JsonValue(result.at(0));
}
// 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element
-ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string();
@@ -759,7 +759,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue
}
// 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected
-ErrorOr<JsonValue, WebDriverError> Session::is_element_selected(StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::is_element_selected(StringView parameter_element_id)
{
// 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());
@@ -783,7 +783,7 @@ ErrorOr<JsonValue, WebDriverError> Session::is_element_selected(StringView param
}
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
-ErrorOr<JsonValue, WebDriverError> Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name)
{
// 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());
@@ -811,7 +811,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_attribute(JsonValue cons
}
// 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property
-ErrorOr<JsonValue, WebDriverError> Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name)
{
// 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());
@@ -833,7 +833,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_property(JsonValue const
}
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
-ErrorOr<JsonValue, WebDriverError> Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name)
{
// 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());
@@ -859,7 +859,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_css_value(JsonValue cons
}
// 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text
-ErrorOr<JsonValue, WebDriverError> Session::get_element_text(JsonValue const&, StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_text(JsonValue const&, StringView parameter_element_id)
{
// 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());
@@ -869,7 +869,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_text(JsonValue const&, S
// FIXME: 3. Let element be the result of trying to get a known connected element with url variable element id.
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value();
@@ -882,7 +882,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_text(JsonValue const&, S
}
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
-ErrorOr<JsonValue, WebDriverError> Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id)
{
// 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());
@@ -900,7 +900,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_tag_name(JsonValue const
}
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
-ErrorOr<JsonValue, WebDriverError> Session::get_element_rect(StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_element_rect(StringView parameter_element_id)
{
// 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());
@@ -930,7 +930,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_rect(StringView paramete
}
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
-ErrorOr<JsonValue, WebDriverError> Session::is_element_enabled(StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::is_element_enabled(StringView parameter_element_id)
{
// 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());
@@ -950,7 +950,7 @@ ErrorOr<JsonValue, WebDriverError> Session::is_element_enabled(StringView parame
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
-ErrorOr<JsonValue, WebDriverError> Session::get_source()
+ErrorOr<JsonValue, Web::WebDriver::Error> 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());
@@ -972,23 +972,23 @@ struct ScriptArguments {
};
// https://w3c.github.io/webdriver/#dfn-extract-the-script-arguments-from-a-request
-static ErrorOr<ScriptArguments, WebDriverError> extract_the_script_arguments_from_a_request(JsonValue const& payload)
+static ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JsonValue const& payload)
{
if (!payload.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object();
// 1. Let script be the result of getting a property named script from the parameters.
// 2. If script is not a String, return error with error code invalid argument.
if (!properties.has_string("script"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload doesn't have a 'script' string property");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have a 'script' string property");
auto script = properties.get("script"sv).as_string();
// 3. Let args be the result of getting a property named args from the parameters.
// 4. If args is not an Array return error with error code invalid argument.
if (!properties.has_array("args"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload doesn't have an 'args' string property");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have an 'args' string property");
auto const& args = properties.get("args"sv).as_array();
// 5. Let arguments be the result of calling the JSON deserialize algorithm with arguments args.
@@ -999,7 +999,7 @@ static ErrorOr<ScriptArguments, WebDriverError> extract_the_script_arguments_fro
}
// 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script
-ErrorOr<JsonValue, WebDriverError> Session::execute_script(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::execute_script(JsonValue const& payload)
{
// 1. Let body and arguments be the result of trying to extract the script arguments from a request with argument parameters.
auto const& [body, arguments] = TRY(extract_the_script_arguments_from_a_request(payload));
@@ -1026,21 +1026,21 @@ ErrorOr<JsonValue, WebDriverError> Session::execute_script(JsonValue const& payl
switch (execute_script_response.result_type()) {
// 6. If promise is still pending and the session script timeout is reached, return error with error code script timeout.
case Web::WebDriver::ExecuteScriptResultType::Timeout:
- return WebDriverError::from_code(ErrorCode::ScriptTimeoutError, "Script timed out");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ScriptTimeoutError, "Script timed out");
// 7. Upon fulfillment of promise with value v, let result be a JSON clone of v, and return success with data result.
case Web::WebDriver::ExecuteScriptResultType::PromiseResolved:
return result;
// 8. Upon rejection of promise with reason r, let result be a JSON clone of r, and return error with error code javascript error and data result.
case Web::WebDriver::ExecuteScriptResultType::PromiseRejected:
case Web::WebDriver::ExecuteScriptResultType::JavaScriptError:
- return WebDriverError::from_code(ErrorCode::JavascriptError, "Script returned an error", move(result));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::JavascriptError, "Script returned an error", move(result));
default:
VERIFY_NOT_REACHED();
}
}
// 13.2.2 Execute Async Script, https://w3c.github.io/webdriver/#dfn-execute-async-script
-ErrorOr<JsonValue, WebDriverError> Session::execute_async_script(JsonValue const& parameters)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::execute_async_script(JsonValue const& parameters)
{
// 1. Let body and arguments by the result of trying to extract the script arguments from a request with argument parameters.
auto [body, arguments] = TRY(extract_the_script_arguments_from_a_request(parameters));
@@ -1067,13 +1067,13 @@ ErrorOr<JsonValue, WebDriverError> Session::execute_async_script(JsonValue const
switch (execute_script_response.result_type()) {
// 6. If promise is still pending and the session script timeout is reached, return error with error code script timeout.
case Web::WebDriver::ExecuteScriptResultType::Timeout:
- return WebDriverError::from_code(ErrorCode::ScriptTimeoutError, "Script timed out");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ScriptTimeoutError, "Script timed out");
// 7. Upon fulfillment of promise with value v, let result be a JSON clone of v, and return success with data result.
case Web::WebDriver::ExecuteScriptResultType::PromiseResolved:
return result;
// 8. Upon rejection of promise with reason r, let result be a JSON clone of r, and return error with error code javascript error and data result.
case Web::WebDriver::ExecuteScriptResultType::PromiseRejected:
- return WebDriverError::from_code(ErrorCode::JavascriptError, "Script returned an error", move(result));
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::JavascriptError, "Script returned an error", move(result));
default:
VERIFY_NOT_REACHED();
}
@@ -1096,7 +1096,7 @@ static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie)
}
// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies
-ErrorOr<JsonValue, WebDriverError> Session::get_all_cookies()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_all_cookies()
{
// 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());
@@ -1120,7 +1120,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_all_cookies()
}
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
-ErrorOr<JsonValue, WebDriverError> Session::get_named_cookie(String const& name)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::get_named_cookie(String const& name)
{
// 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());
@@ -1137,15 +1137,15 @@ ErrorOr<JsonValue, WebDriverError> Session::get_named_cookie(String const& name)
}
// 4. Otherwise, return error with error code no such cookie.
- return WebDriverError::from_code(ErrorCode::NoSuchCookie, "Cookie not found");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchCookie, "Cookie not found");
}
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
-ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::add_cookie(JsonValue const& payload)
{
// 1. Let data be the result of getting a property named cookie from the parameters argument.
if (!payload.is_object() || !payload.as_object().has_object("cookie"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload doesn't have a cookie object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have a cookie object");
auto const& maybe_data = payload.as_object().get("cookie"sv);
@@ -1153,12 +1153,12 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
// return error with error code invalid argument.
// NOTE: Table is here: https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion
if (!maybe_data.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Value \"cookie\' is not an object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Value \"cookie\' is not an object");
auto const& data = maybe_data.as_object();
if (!data.has("name"sv) || !data.has("value"sv))
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object doesn't contain all required keys");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Cookie-Object doesn't contain all required keys");
// 3. 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());
@@ -1174,17 +1174,17 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
// or cookie expiry time is not an integer type, or it less than 0 or greater than the maximum safe integer,
// return error with error code invalid argument.
if (data.get("name"sv).is_null() || data.get("value"sv).is_null())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: name or value are null");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Cookie-Object is malformed: name or value are null");
if (data.has("secure"sv) && !data.get("secure"sv).is_bool())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: secure is not bool");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Cookie-Object is malformed: secure is not bool");
if (data.has("httpOnly"sv) && !data.get("httpOnly"sv).is_bool())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: httpOnly is not bool");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Cookie-Object is malformed: httpOnly is not bool");
Optional<Core::DateTime> expiry_time;
if (data.has("expiry"sv)) {
auto expiry_argument = data.get("expiry"sv);
if (!expiry_argument.is_u32()) {
// NOTE: less than 0 or greater than safe integer are handled by the JSON parser
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: expiry is not u32");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Cookie-Object is malformed: expiry is not u32");
}
expiry_time = Core::DateTime::from_timestamp(expiry_argument.as_u32());
}
@@ -1196,12 +1196,12 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto name_attribute = data.get("name"sv); name_attribute.is_string())
cookie.name = name_attribute.as_string();
else
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect name attribute to be string");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Expect name attribute to be string");
if (auto value_attribute = data.get("value"sv); value_attribute.is_string())
cookie.value = value_attribute.as_string();
else
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect value attribute to be string");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Expect value attribute to be string");
// Cookie path
// The value if the entry exists, otherwise "/".
@@ -1209,7 +1209,7 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto path_attribute = data.get("path"sv); path_attribute.is_string())
cookie.path = path_attribute.as_string();
else
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect path attribute to be string");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Expect path attribute to be string");
} else {
cookie.path = "/";
}
@@ -1221,7 +1221,7 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto domain_attribute = data.get("domain"sv); domain_attribute.is_string())
cookie.domain = domain_attribute.as_string();
else
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect domain attribute to be string");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Expect domain attribute to be string");
}
// Cookie secure only
@@ -1277,7 +1277,7 @@ void Session::delete_cookies(Optional<StringView> const& name)
}
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
-ErrorOr<JsonValue, WebDriverError> Session::delete_cookie(StringView name)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::delete_cookie(StringView name)
{
// 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());
@@ -1292,7 +1292,7 @@ ErrorOr<JsonValue, WebDriverError> Session::delete_cookie(StringView name)
}
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
-ErrorOr<JsonValue, WebDriverError> Session::delete_all_cookies()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::delete_all_cookies()
{
// 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());
@@ -1307,13 +1307,13 @@ ErrorOr<JsonValue, WebDriverError> Session::delete_all_cookies()
}
// https://w3c.github.io/webdriver/#dfn-encoding-a-canvas-as-base64
-static ErrorOr<String, WebDriverError> encode_bitmap_as_canvas_element(Gfx::Bitmap const& bitmap)
+static ErrorOr<String, Web::WebDriver::Error> encode_bitmap_as_canvas_element(Gfx::Bitmap const& bitmap)
{
// FIXME: 1. If the canvas elementā€™s bitmapā€™s origin-clean flag is set to false, return error with error code unable to capture screen.
// 2. If the canvas elementā€™s bitmap has no pixels (i.e. either its horizontal dimension or vertical dimension is zero) then return error with error code unable to capture screen.
if (bitmap.width() == 0 || bitmap.height() == 0)
- return WebDriverError::from_code(ErrorCode::UnableToCaptureScreen, "Captured screenshot is empty"sv);
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnableToCaptureScreen, "Captured screenshot is empty"sv);
// 3. Let file be a serialization of the canvas elementā€™s bitmap as a file, using "image/png" as an argument.
auto file = Gfx::PNGWriter::encode(bitmap);
@@ -1333,7 +1333,7 @@ static ErrorOr<String, WebDriverError> encode_bitmap_as_canvas_element(Gfx::Bitm
}
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
-ErrorOr<JsonValue, WebDriverError> Session::take_screenshot()
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::take_screenshot()
{
// 1. If the current top-level 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());
@@ -1343,7 +1343,7 @@ ErrorOr<JsonValue, WebDriverError> Session::take_screenshot()
// b. Let screenshot result be the result of trying to call draw a bounding box from the framebuffer, given root rect as an argument.
auto screenshot = m_browser_connection->take_screenshot();
if (!screenshot.is_valid())
- return WebDriverError::from_code(ErrorCode::UnableToCaptureScreen, "Unable to capture screenshot"sv);
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnableToCaptureScreen, "Unable to capture screenshot"sv);
// c. Let canvas be a canvas element of screenshot resultā€™s data.
// d. Let encoding result be the result of trying encoding a canvas as Base64 canvas.
@@ -1355,7 +1355,7 @@ ErrorOr<JsonValue, WebDriverError> Session::take_screenshot()
}
// 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot
-ErrorOr<JsonValue, WebDriverError> Session::take_element_screenshot(StringView parameter_element_id)
+ErrorOr<JsonValue, Web::WebDriver::Error> Session::take_element_screenshot(StringView parameter_element_id)
{
// 1. If the current top-level 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());
@@ -1373,7 +1373,7 @@ ErrorOr<JsonValue, WebDriverError> Session::take_element_screenshot(StringView p
// b. Let screenshot result be the result of trying to call draw a bounding box from the framebuffer, given element rect as an argument.
auto screenshot = m_browser_connection->take_element_screenshot(element_id);
if (!screenshot.is_valid())
- return WebDriverError::from_code(ErrorCode::UnableToCaptureScreen, "Unable to capture screenshot"sv);
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnableToCaptureScreen, "Unable to capture screenshot"sv);
// c. Let canvas be a canvas element of screenshot resultā€™s data.
// d. Let encoding result be the result of trying encoding a canvas as Base64 canvas.
diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h
index 99b0071507..d1ffcfa09f 100644
--- a/Userland/Services/WebDriver/Session.h
+++ b/Userland/Services/WebDriver/Session.h
@@ -11,9 +11,9 @@
#include <AK/Error.h>
#include <AK/JsonValue.h>
#include <AK/RefPtr.h>
+#include <LibWeb/WebDriver/Error.h>
#include <WebDriver/BrowserConnection.h>
#include <WebDriver/TimeoutsConfiguration.h>
-#include <WebDriver/WebDriverError.h>
#include <unistd.h>
namespace WebDriver {
@@ -34,55 +34,55 @@ public:
i32 id;
};
- ErrorOr<Window*, WebDriverError> current_window();
- ErrorOr<void, WebDriverError> check_for_open_top_level_browsing_context_or_return_error();
+ ErrorOr<Window*, Web::WebDriver::Error> current_window();
+ ErrorOr<void, Web::WebDriver::Error> check_for_open_top_level_browsing_context_or_return_error();
String const& current_window_handle() { return m_current_window_handle; }
ErrorOr<void> start();
ErrorOr<void> stop();
JsonObject get_timeouts();
- ErrorOr<JsonValue, WebDriverError> set_timeouts(JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> navigate_to(JsonValue const& url);
- ErrorOr<JsonValue, WebDriverError> get_current_url();
- ErrorOr<JsonValue, WebDriverError> back();
- ErrorOr<JsonValue, WebDriverError> forward();
- ErrorOr<JsonValue, WebDriverError> refresh();
- ErrorOr<JsonValue, WebDriverError> get_title();
- ErrorOr<JsonValue, WebDriverError> get_window_handle();
- ErrorOr<void, Variant<WebDriverError, Error>> close_window();
- ErrorOr<JsonValue, WebDriverError> get_window_handles() const;
- ErrorOr<JsonValue, WebDriverError> get_window_rect();
- ErrorOr<JsonValue, WebDriverError> set_window_rect(JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> maximize_window();
- ErrorOr<JsonValue, WebDriverError> minimize_window();
- ErrorOr<JsonValue, WebDriverError> find_element(JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> find_elements(JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);
- ErrorOr<JsonValue, WebDriverError> find_elements_from_element(JsonValue const& payload, StringView parameter_element_id);
- ErrorOr<JsonValue, WebDriverError> is_element_selected(StringView element_id);
- ErrorOr<JsonValue, WebDriverError> get_element_attribute(JsonValue const& payload, StringView element_id, StringView name);
- ErrorOr<JsonValue, WebDriverError> get_element_property(JsonValue const& payload, StringView element_id, StringView name);
- 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_element_rect(StringView element_id);
- ErrorOr<JsonValue, WebDriverError> is_element_enabled(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();
- ErrorOr<JsonValue, WebDriverError> get_named_cookie(String const& name);
- ErrorOr<JsonValue, WebDriverError> add_cookie(JsonValue const& payload);
- ErrorOr<JsonValue, WebDriverError> delete_cookie(StringView name);
- ErrorOr<JsonValue, WebDriverError> delete_all_cookies();
- ErrorOr<JsonValue, WebDriverError> take_screenshot();
- ErrorOr<JsonValue, WebDriverError> take_element_screenshot(StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> set_timeouts(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> navigate_to(JsonValue const& url);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_current_url();
+ ErrorOr<JsonValue, Web::WebDriver::Error> back();
+ ErrorOr<JsonValue, Web::WebDriver::Error> forward();
+ ErrorOr<JsonValue, Web::WebDriver::Error> refresh();
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_title();
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_window_handle();
+ ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_window_handles() const;
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_window_rect();
+ ErrorOr<JsonValue, Web::WebDriver::Error> set_window_rect(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> maximize_window();
+ ErrorOr<JsonValue, Web::WebDriver::Error> minimize_window();
+ ErrorOr<JsonValue, Web::WebDriver::Error> find_element(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> find_elements(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> find_elements_from_element(JsonValue const& payload, StringView parameter_element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> is_element_selected(StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_attribute(JsonValue const& payload, StringView element_id, StringView name);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_property(JsonValue const& payload, StringView element_id, StringView name);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_text(JsonValue const& payload, StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_tag_name(JsonValue const& payload, StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_element_rect(StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> is_element_enabled(StringView element_id);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_source();
+ ErrorOr<JsonValue, Web::WebDriver::Error> execute_script(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> execute_async_script(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_all_cookies();
+ ErrorOr<JsonValue, Web::WebDriver::Error> get_named_cookie(String const& name);
+ ErrorOr<JsonValue, Web::WebDriver::Error> add_cookie(JsonValue const& payload);
+ ErrorOr<JsonValue, Web::WebDriver::Error> delete_cookie(StringView name);
+ ErrorOr<JsonValue, Web::WebDriver::Error> delete_all_cookies();
+ ErrorOr<JsonValue, Web::WebDriver::Error> take_screenshot();
+ ErrorOr<JsonValue, Web::WebDriver::Error> take_element_screenshot(StringView element_id);
private:
void delete_cookies(Optional<StringView> const& name = {});
- ErrorOr<JsonArray, WebDriverError> find(LocalElement const& start_node, StringView location_strategy, StringView selector);
+ ErrorOr<JsonArray, Web::WebDriver::Error> find(LocalElement const& start_node, StringView location_strategy, StringView selector);
- using ElementLocationStrategyHandler = ErrorOr<Vector<LocalElement>, WebDriverError> (Session::*)(LocalElement const&, StringView);
+ using ElementLocationStrategyHandler = ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> (Session::*)(LocalElement const&, StringView);
struct LocatorStrategy {
String name;
ElementLocationStrategyHandler handler;
@@ -90,11 +90,11 @@ private:
static Vector<LocatorStrategy> s_locator_strategies;
- ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_css_selectors(LocalElement const&, StringView);
- ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_link_text(LocalElement const&, StringView);
- ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_partial_link_text(LocalElement const&, StringView);
- ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_tag_name(LocalElement const&, StringView);
- ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_x_path(LocalElement const&, StringView);
+ ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> locator_strategy_css_selectors(LocalElement const&, StringView);
+ ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> locator_strategy_link_text(LocalElement const&, StringView);
+ ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> locator_strategy_partial_link_text(LocalElement const&, StringView);
+ ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> locator_strategy_tag_name(LocalElement const&, StringView);
+ ErrorOr<Vector<LocalElement>, Web::WebDriver::Error> locator_strategy_x_path(LocalElement const&, StringView);
NonnullRefPtr<Client> m_client;
bool m_started { false };
diff --git a/Userland/Services/WebDriver/TimeoutsConfiguration.cpp b/Userland/Services/WebDriver/TimeoutsConfiguration.cpp
index 91c825ae3d..5c73766c47 100644
--- a/Userland/Services/WebDriver/TimeoutsConfiguration.cpp
+++ b/Userland/Services/WebDriver/TimeoutsConfiguration.cpp
@@ -6,7 +6,6 @@
#include <AK/JsonObject.h>
#include <WebDriver/TimeoutsConfiguration.h>
-#include <WebDriver/WebDriverError.h>
namespace WebDriver {
@@ -35,7 +34,7 @@ JsonObject timeouts_object(TimeoutsConfiguration const& timeouts)
}
// https://w3c.github.io/webdriver/#ref-for-dfn-json-deserialize-3
-ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_configuration(JsonValue const& value)
+ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_timeouts_configuration(JsonValue const& value)
{
constexpr i64 max_safe_integer = 9007199254740991;
@@ -44,7 +43,7 @@ ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_co
// 2. If value is not a JSON Object, return error with error code invalid argument.
if (!value.is_object())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object");
// 3. If value has a property with the key "script":
if (value.as_object().has("script"sv)) {
@@ -53,7 +52,7 @@ ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_co
// 2. If script duration is a number and less than 0 or greater than maximum safe integer, or it is not null, return error with error code invalid argument.
if ((script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) || !script_duration.is_null())
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid script duration");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid script duration");
// 3. Set timeoutsā€™s script timeout to script duration.
timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64();
@@ -66,7 +65,7 @@ ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_co
// 2. If page load duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer)
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid page load duration");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid page load duration");
// 3. Set timeoutsā€™s page load timeout to page load duration.
timeouts.page_load_timeout = page_load_duration.to_u64();
@@ -79,7 +78,7 @@ ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_co
// 2. If implicit duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer)
- return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid implicit duration");
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid implicit duration");
// 3. Set timeoutsā€™s implicit wait timeout to implicit duration.
timeouts.implicit_wait_timeout = implicit_duration.to_u64();
diff --git a/Userland/Services/WebDriver/TimeoutsConfiguration.h b/Userland/Services/WebDriver/TimeoutsConfiguration.h
index f5c156c3bd..8b20a454ce 100644
--- a/Userland/Services/WebDriver/TimeoutsConfiguration.h
+++ b/Userland/Services/WebDriver/TimeoutsConfiguration.h
@@ -6,9 +6,9 @@
#pragma once
-#include "WebDriverError.h"
#include <AK/Forward.h>
#include <AK/Optional.h>
+#include <LibWeb/WebDriver/Error.h>
namespace WebDriver {
@@ -20,6 +20,6 @@ struct TimeoutsConfiguration {
};
JsonObject timeouts_object(TimeoutsConfiguration const&);
-ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_configuration(JsonValue const&);
+ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_timeouts_configuration(JsonValue const&);
}