1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

WebDriver: Use WebDriverError::from_code() for all error creation

This commit is contained in:
Sam Atkins 2022-10-20 14:00:49 +01:00 committed by Linus Groh
parent 9393904073
commit 3232622255
4 changed files with 86 additions and 87 deletions

View file

@ -249,7 +249,7 @@ ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpReq
// https://w3c.github.io/webdriver/webdriver-spec.html#routing-requests // https://w3c.github.io/webdriver/webdriver-spec.html#routing-requests
if (!resource.starts_with(m_prefix)) if (!resource.starts_with(m_prefix))
return WebDriverError { 404, "unknown command", "The resource doesn't start with the prefix." }; return WebDriverError::from_code(ErrorCode::UnknownCommand, "The resource doesn't start with the prefix.");
Vector<StringView> resource_split = resource.substring_view(m_prefix.length()).split_view('/', true); Vector<StringView> resource_split = resource.substring_view(m_prefix.length()).split_view('/', true);
Vector<StringView> parameters; Vector<StringView> parameters;
@ -288,25 +288,25 @@ ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpReq
// Matched a path, but didn't match a known method // Matched a path, but didn't match a known method
if (matched_path) { if (matched_path) {
dbgln_if(WEBDRIVER_DEBUG, "- A path matched, but method didn't. :^("); dbgln_if(WEBDRIVER_DEBUG, "- A path matched, but method didn't. :^(");
return WebDriverError { 405, "unknown method", "The command matched a known URL but did not match a method for that URL." }; return WebDriverError::from_code(ErrorCode::UnknownMethod, "The command matched a known URL but did not match a method for that URL.");
} }
// Didn't have any match // Didn't have any match
dbgln_if(WEBDRIVER_DEBUG, "- No matches. :^("); dbgln_if(WEBDRIVER_DEBUG, "- No matches. :^(");
return WebDriverError { 404, "unknown command", "The command was not recognized." }; return WebDriverError::from_code(ErrorCode::UnknownCommand, "The command was not recognized.");
} }
ErrorOr<Session*, WebDriverError> Client::find_session_with_id(StringView session_id) ErrorOr<Session*, WebDriverError> Client::find_session_with_id(StringView session_id)
{ {
auto session_id_or_error = session_id.to_uint<>(); auto session_id_or_error = session_id.to_uint<>();
if (!session_id_or_error.has_value()) if (!session_id_or_error.has_value())
return WebDriverError { 404, "invalid session id", "Invalid session id" }; return WebDriverError::from_code(ErrorCode::InvalidSessionId, "Invalid session id");
for (auto& session : Client::s_sessions) { for (auto& session : Client::s_sessions) {
if (session.session_id() == session_id_or_error.value()) if (session.session_id() == session_id_or_error.value())
return &session; return &session;
} }
return WebDriverError { 404, "invalid session id", "Invalid session id" }; return WebDriverError::from_code(ErrorCode::InvalidSessionId, "Invalid session id");
} }
void Client::close_session(unsigned session_id) void Client::close_session(unsigned session_id)
@ -360,7 +360,7 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_new_session(Vector<StringView>
NonnullOwnPtr<Session> session = make<Session>(session_id, *this); NonnullOwnPtr<Session> session = make<Session>(session_id, *this);
auto start_result = session->start(); auto start_result = session->start();
if (start_result.is_error()) { if (start_result.is_error()) {
return WebDriverError { 500, "Failed to start session", start_result.error().string_literal() }; return WebDriverError::from_code(ErrorCode::SessionNotCreated, String::formatted("Failed to start session: {}", start_result.error().string_literal()));
} }
// FIXME: 8. Set the current session to session. // FIXME: 8. Set the current session to session.
@ -404,9 +404,8 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_session(Vector<StringVi
auto* session = TRY(find_session_with_id(parameters[0])); auto* session = TRY(find_session_with_id(parameters[0]));
auto stop_result = session->stop(); auto stop_result = session->stop();
if (stop_result.is_error()) { if (stop_result.is_error())
return WebDriverError { 500, "unsupported operation", stop_result.error().string_literal() }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, stop_result.error().string_literal());
}
// 2. Return success with data null. // 2. Return success with data null.
return make_json_value(JsonValue()); return make_json_value(JsonValue());

View file

@ -84,7 +84,7 @@ private:
Variant<WebDriverError, Error> error = result.release_error(); Variant<WebDriverError, Error> error = result.release_error();
if (error.has<WebDriverError>()) if (error.has<WebDriverError>())
return error.get<WebDriverError>(); return error.get<WebDriverError>();
return WebDriverError { 500, "unsupported operation", error.get<Error>().string_literal() }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
} }
return result.release_value(); return result.release_value();
@ -95,7 +95,7 @@ private:
Variant<WebDriverError, Error> error = result.release_error(); Variant<WebDriverError, Error> error = result.release_error();
if (error.has<WebDriverError>()) if (error.has<WebDriverError>())
return error.get<WebDriverError>(); return error.get<WebDriverError>();
return WebDriverError { 500, "unsupported operation", error.get<Error>().string_literal() }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
} }
return {}; return {};
} }

View file

@ -102,13 +102,13 @@ ErrorOr<JsonValue, WebDriverError> 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. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME 2. Handle any user prompts and return its value if it is an error. // FIXME 2. Handle any user prompts and return its value if it is an error.
// 3. If the url property is missing from the parameters argument or it is not a string, return error with error code invalid argument. // 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)) { if (!payload.is_object() || !payload.as_object().has_string("url"sv)) {
return WebDriverError { 400, "invalid argument", "Payload doesn't have a string url" }; return WebDriverError::from_code(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. // 4. Let url be the result of getting a property named url from the parameters argument.
@ -138,7 +138,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_current_url()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -155,7 +155,7 @@ ErrorOr<JsonValue, WebDriverError> Session::back()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -178,7 +178,7 @@ ErrorOr<JsonValue, WebDriverError> Session::forward()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -201,7 +201,7 @@ ErrorOr<JsonValue, WebDriverError> Session::refresh()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -226,7 +226,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_title()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -241,7 +241,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_window_handle()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// 2. Return success with data being the window handle associated with the current top-level browsing context. // 2. Return success with data being the window handle associated with the current top-level browsing context.
return m_current_window_handle; return m_current_window_handle;
@ -253,7 +253,7 @@ ErrorOr<void, Variant<WebDriverError, Error>> Session::close_window()
// 1. If the current top-level browsing context is no longer open, return error with error code no such window. // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return Variant<WebDriverError, Error>(WebDriverError { 404, "no such window", "Window not found" }); return Variant<WebDriverError, Error>(WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found"));
// 2. Close the current top-level browsing context. // 2. Close the current top-level browsing context.
m_windows.remove(m_current_window_handle); m_windows.remove(m_current_window_handle);
@ -326,13 +326,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. // 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; }); auto location_strategy_handler = s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; });
if (!location_strategy_handler.has_value()) if (!location_strategy_handler.has_value())
return WebDriverError { 400, "invalid argument", "No valid location strategy" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
auto elements_or_error = (this->*location_strategy_handler.value().handler)(start_node, selector); 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. // 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()) if (elements_or_error.is_error())
return WebDriverError { 400, "invalid selector", String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message) }; return WebDriverError::from_code(ErrorCode::InvalidSelector, String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message));
auto elements = elements_or_error.release_value(); auto elements = elements_or_error.release_value();
@ -368,7 +368,7 @@ ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy
auto elements_ids = m_browser_connection->query_selector_all(start_node.id, selector); auto elements_ids = m_browser_connection->query_selector_all(start_node.id, selector);
if (!elements_ids.has_value()) if (!elements_ids.has_value())
return WebDriverError { 400, "invalid selector", "query_selector_all returned failed!" }; return WebDriverError::from_code(ErrorCode::InvalidSelector, "query_selector_all returned failed!");
Vector<Session::LocalElement> elements; Vector<Session::LocalElement> elements;
for (auto id : elements_ids.release_value()) { for (auto id : elements_ids.release_value()) {
@ -383,64 +383,64 @@ ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_link_text(Session::LocalElement const&, StringView const&) ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_link_text(Session::LocalElement const&, StringView const&)
{ {
// FIXME: Implement // FIXME: Implement
return WebDriverError { 501, "not implemented", "locator strategy link text" }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy link text");
} }
// https://w3c.github.io/webdriver/#partial-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 const&) ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_partial_link_text(Session::LocalElement const&, StringView const&)
{ {
// FIXME: Implement // FIXME: Implement
return WebDriverError { 501, "not implemented", "locator strategy partial link text" }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy partial link text");
} }
// https://w3c.github.io/webdriver/#tag-name // https://w3c.github.io/webdriver/#tag-name
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView const&) ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView const&)
{ {
// FIXME: Implement // FIXME: Implement
return WebDriverError { 501, "not implemented", "locator strategy tag name" }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy tag name");
} }
// https://w3c.github.io/webdriver/#xpath // https://w3c.github.io/webdriver/#xpath
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_x_path(Session::LocalElement const&, StringView const&) ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_x_path(Session::LocalElement const&, StringView const&)
{ {
// FIXME: Implement // FIXME: Implement
return WebDriverError { 501, "not implemented", "locator strategy XPath" }; return WebDriverError::from_code(ErrorCode::UnsupportedOperation, "Not implemented: locator strategy XPath");
} }
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payload) ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payload)
{ {
if (!payload.is_object()) if (!payload.is_object())
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object(); auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using". // 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv)) if (!properties.has("using"sv))
return WebDriverError { 400, "invalid argument", "No property called 'using' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv); auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string()) if (!maybe_location_strategy.is_string())
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_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. // 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()) if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return WebDriverError { 400, "invalid argument", "No valid location strategy" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value". // 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument. // 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv)) if (!properties.has("value"sv))
return WebDriverError { 400, "invalid argument", "No property called 'value' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv); auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string()) if (!maybe_selector.is_string())
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string(); auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window. // 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 6. Handle any user prompts and return its value if it is an error. // FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -449,7 +449,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payloa
// 8. If start node is null, return error with error code no such element. // 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value()) if (!maybe_start_node_id.has_value())
return WebDriverError { 404, "no such element", "document element does not exist" }; return WebDriverError::from_code(ErrorCode::NoSuchElement, "document element does not exist");
auto start_node_id = maybe_start_node_id.release_value(); auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id }; LocalElement start_node = { start_node_id };
@ -459,7 +459,7 @@ 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. // 10. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty()) if (result.is_empty())
return WebDriverError { 404, "no such element", "the requested element does not exist" }; return WebDriverError::from_code(ErrorCode::NoSuchElement, "The requested element does not exist");
return JsonValue(result.at(0)); return JsonValue(result.at(0));
} }
@ -468,36 +468,36 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payloa
ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& payload) ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& payload)
{ {
if (!payload.is_object()) if (!payload.is_object())
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object(); auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using". // 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv)) if (!properties.has("using"sv))
return WebDriverError { 400, "invalid argument", "No property called 'using' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv); auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string()) if (!maybe_location_strategy.is_string())
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_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. // 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()) if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return WebDriverError { 400, "invalid argument", "No valid location strategy" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value". // 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument. // 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv)) if (!properties.has("value"sv))
return WebDriverError { 400, "invalid argument", "No property called 'value' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv); auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string()) if (!maybe_selector.is_string())
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string(); auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window. // 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 6. Handle any user prompts and return its value if it is an error. // FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -506,7 +506,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& paylo
// 8. If start node is null, return error with error code no such element. // 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value()) if (!maybe_start_node_id.has_value())
return WebDriverError { 404, "no such element", "document element does not exist" }; return WebDriverError::from_code(ErrorCode::NoSuchElement, "document element does not exist");
auto start_node_id = maybe_start_node_id.release_value(); auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id }; LocalElement start_node = { start_node_id };
@ -520,36 +520,36 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& paylo
ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id) ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id)
{ {
if (!payload.is_object()) if (!payload.is_object())
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object(); auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using". // 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv)) if (!properties.has("using"sv))
return WebDriverError { 400, "invalid argument", "No property called 'using' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv); auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string()) if (!maybe_location_strategy.is_string())
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_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. // 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()) if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return WebDriverError { 400, "invalid argument", "No valid location strategy" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value". // 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument. // 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv)) if (!properties.has("value"sv))
return WebDriverError { 400, "invalid argument", "No property called 'value' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv); auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string()) if (!maybe_selector.is_string())
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string(); auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window. // 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 6. Handle any user prompts and return its value if it is an error. // FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -559,7 +559,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue
auto maybe_element_id = parameter_element_id.to_int(); auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value()) if (!maybe_element_id.has_value())
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value(); auto element_id = maybe_element_id.release_value();
LocalElement start_node = { element_id }; LocalElement start_node = { element_id };
@ -569,7 +569,7 @@ 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. // 9. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty()) if (result.is_empty())
return WebDriverError { 404, "no such element", "the requested element does not exist" }; return WebDriverError::from_code(ErrorCode::NoSuchElement, "The requested element does not exist");
return JsonValue(result.at(0)); return JsonValue(result.at(0));
} }
@ -578,36 +578,36 @@ ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue
ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id) ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id)
{ {
if (!payload.is_object()) if (!payload.is_object())
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
auto const& properties = payload.as_object(); auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using". // 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv)) if (!properties.has("using"sv))
return WebDriverError { 400, "invalid argument", "No property called 'using' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'using' present");
auto const& maybe_location_strategy = properties.get("using"sv); auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string()) if (!maybe_location_strategy.is_string())
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'using' is not a String");
auto location_strategy = maybe_location_strategy.to_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. // 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()) if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return WebDriverError { 400, "invalid argument", "No valid location strategy" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No valid location strategy");
// 3. Let selector be the result of getting a property called "value". // 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument. // 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv)) if (!properties.has("value"sv))
return WebDriverError { 400, "invalid argument", "No property called 'value' present" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "No property called 'value' present");
auto const& maybe_selector = properties.get("value"sv); auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string()) if (!maybe_selector.is_string())
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Property 'value' is not a String");
auto selector = maybe_selector.to_string(); auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window. // 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 6. Handle any user prompts and return its value if it is an error. // FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -617,7 +617,7 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue
auto maybe_element_id = parameter_element_id.to_int(); auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value()) if (!maybe_element_id.has_value())
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value(); auto element_id = maybe_element_id.release_value();
LocalElement start_node = { element_id }; LocalElement start_node = { element_id };
@ -633,7 +633,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_attribute(JsonValue cons
// 1. If the current browsing context is no longer open, return error with error code no such window. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -642,7 +642,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_attribute(JsonValue cons
// For now the element is only represented by its ID // For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int(); auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value()) if (!maybe_element_id.has_value())
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value(); auto element_id = maybe_element_id.release_value();
@ -669,7 +669,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_property(JsonValue const
// 1. If the current browsing context is no longer open, return error with error code no such window. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts and return its value if it is an error. // FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -678,7 +678,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_property(JsonValue const
// For now the element is only represented by its ID // For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int(); auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value()) if (!maybe_element_id.has_value())
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value(); auto element_id = maybe_element_id.release_value();
@ -708,7 +708,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_element_css_value(JsonValue cons
// For now the element is only represented by its ID // For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int(); auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value()) if (!maybe_element_id.has_value())
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Element ID is not an i32");
auto element_id = maybe_element_id.release_value(); auto element_id = maybe_element_id.release_value();
@ -749,7 +749,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_all_cookies()
// 1. If the current browsing context is no longer open, return error with error code no such window. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts, and return its value if it is an error. // FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -775,7 +775,7 @@ ErrorOr<JsonValue, WebDriverError> 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. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts, and return its value if it is an error. // FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -789,7 +789,7 @@ ErrorOr<JsonValue, WebDriverError> Session::get_named_cookie(String const& name)
} }
// 4. Otherwise, return error with error code no such cookie. // 4. Otherwise, return error with error code no such cookie.
return WebDriverError { 404, "no such cookie", "Cookie not found" }; return WebDriverError::from_code(ErrorCode::NoSuchCookie, "Cookie not found");
} }
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie // 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
@ -797,7 +797,7 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
{ {
// 1. Let data be the result of getting a property named cookie from the parameters argument. // 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)) if (!payload.is_object() || !payload.as_object().has_object("cookie"sv))
return WebDriverError { 400, "invalid argument", "Payload doesn't have a cookie object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload doesn't have a cookie object");
auto const& maybe_data = payload.as_object().get("cookie"sv); auto const& maybe_data = payload.as_object().get("cookie"sv);
@ -805,17 +805,17 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
// return error with error code invalid argument. // return error with error code invalid argument.
// NOTE: Table is here: https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion // NOTE: Table is here: https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion
if (!maybe_data.is_object()) if (!maybe_data.is_object())
return WebDriverError { 400, "invalid argument", "Value \"cookie\' is not an object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Value \"cookie\' is not an object");
auto const& data = maybe_data.as_object(); auto const& data = maybe_data.as_object();
if (!data.has("name"sv) || !data.has("value"sv)) if (!data.has("name"sv) || !data.has("value"sv))
return WebDriverError { 400, "invalid argument", "Cookie-Object doesn't contain all required keys" }; return WebDriverError::from_code(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. // 3. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 4. Handle any user prompts, and return its value if it is an error. // FIXME: 4. Handle any user prompts, and return its value if it is an error.
@ -828,17 +828,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, // 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. // return error with error code invalid argument.
if (data.get("name"sv).is_null() || data.get("value"sv).is_null()) if (data.get("name"sv).is_null() || data.get("value"sv).is_null())
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: name or value are null" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: name or value are null");
if (data.has("secure"sv) && !data.get("secure"sv).is_bool()) if (data.has("secure"sv) && !data.get("secure"sv).is_bool())
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: secure is not bool" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: secure is not bool");
if (data.has("httpOnly"sv) && !data.get("httpOnly"sv).is_bool()) if (data.has("httpOnly"sv) && !data.get("httpOnly"sv).is_bool())
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: httpOnly is not bool" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: httpOnly is not bool");
Optional<Core::DateTime> expiry_time; Optional<Core::DateTime> expiry_time;
if (data.has("expiry"sv)) { if (data.has("expiry"sv)) {
auto expiry_argument = data.get("expiry"sv); auto expiry_argument = data.get("expiry"sv);
if (!expiry_argument.is_u32()) { if (!expiry_argument.is_u32()) {
// NOTE: less than 0 or greater than safe integer are handled by the JSON parser // NOTE: less than 0 or greater than safe integer are handled by the JSON parser
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: expiry is not u32" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Cookie-Object is malformed: expiry is not u32");
} }
expiry_time = Core::DateTime::from_timestamp(expiry_argument.as_u32()); expiry_time = Core::DateTime::from_timestamp(expiry_argument.as_u32());
} }
@ -850,12 +850,12 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto name_attribute = data.get("name"sv); name_attribute.is_string()) if (auto name_attribute = data.get("name"sv); name_attribute.is_string())
cookie.name = name_attribute.as_string(); cookie.name = name_attribute.as_string();
else else
return WebDriverError { 400, "invalid argument", "Expect name attribute to be string" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect name attribute to be string");
if (auto value_attribute = data.get("value"sv); value_attribute.is_string()) if (auto value_attribute = data.get("value"sv); value_attribute.is_string())
cookie.value = value_attribute.as_string(); cookie.value = value_attribute.as_string();
else else
return WebDriverError { 400, "invalid argument", "Expect value attribute to be string" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect value attribute to be string");
// Cookie path // Cookie path
// The value if the entry exists, otherwise "/". // The value if the entry exists, otherwise "/".
@ -863,7 +863,7 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto path_attribute = data.get("path"sv); path_attribute.is_string()) if (auto path_attribute = data.get("path"sv); path_attribute.is_string())
cookie.path = path_attribute.as_string(); cookie.path = path_attribute.as_string();
else else
return WebDriverError { 400, "invalid argument", "Expect path attribute to be string" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect path attribute to be string");
} else { } else {
cookie.path = "/"; cookie.path = "/";
} }
@ -875,7 +875,7 @@ ErrorOr<JsonValue, WebDriverError> Session::add_cookie(JsonValue const& payload)
if (auto domain_attribute = data.get("domain"sv); domain_attribute.is_string()) if (auto domain_attribute = data.get("domain"sv); domain_attribute.is_string())
cookie.domain = domain_attribute.as_string(); cookie.domain = domain_attribute.as_string();
else else
return WebDriverError { 400, "invalid argument", "Expect domain attribute to be string" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Expect domain attribute to be string");
} }
// Cookie secure only // Cookie secure only
@ -936,7 +936,7 @@ ErrorOr<JsonValue, WebDriverError> Session::delete_cookie(StringView const& name
// 1. If the current browsing context is no longer open, return error with error code no such window. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts, and return its value if it is an error. // FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -953,7 +953,7 @@ ErrorOr<JsonValue, WebDriverError> Session::delete_all_cookies()
// 1. If the current browsing context is no longer open, return error with error code no such window. // 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window(); auto current_window = this->current_window();
if (!current_window.has_value()) if (!current_window.has_value())
return WebDriverError { 404, "no such window", "Window not found" }; return WebDriverError::from_code(ErrorCode::NoSuchWindow, "Window not found");
// FIXME: 2. Handle any user prompts, and return its value if it is an error. // FIXME: 2. Handle any user prompts, and return its value if it is an error.

View file

@ -44,7 +44,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. // 2. If value is not a JSON Object, return error with error code invalid argument.
if (!value.is_object()) if (!value.is_object())
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object");
// 3. If value has a property with the key "script": // 3. If value has a property with the key "script":
if (value.as_object().has("script"sv)) { if (value.as_object().has("script"sv)) {
@ -53,7 +53,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. // 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()) if ((script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) || !script_duration.is_null())
return WebDriverError { 400, "invalid argument", "Invalid script duration" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid script duration");
// 3. Set timeoutss script timeout to script duration. // 3. Set timeoutss script timeout to script duration.
timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64(); timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64();
@ -66,7 +66,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. // 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) if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer)
return WebDriverError { 400, "invalid argument", "Invalid page load duration" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid page load duration");
// 3. Set timeoutss page load timeout to page load duration. // 3. Set timeoutss page load timeout to page load duration.
timeouts.page_load_timeout = page_load_duration.to_u64(); timeouts.page_load_timeout = page_load_duration.to_u64();
@ -79,7 +79,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. // 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) if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer)
return WebDriverError { 400, "invalid argument", "Invalid implicit duration" }; return WebDriverError::from_code(ErrorCode::InvalidArgument, "Invalid implicit duration");
// 3. Set timeoutss implicit wait timeout to implicit duration. // 3. Set timeoutss implicit wait timeout to implicit duration.
timeouts.implicit_wait_timeout = implicit_duration.to_u64(); timeouts.implicit_wait_timeout = implicit_duration.to_u64();