From f0a8e3bc05c0d2d0fb21fd5cc1ea9c80c7982bf8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 19 Oct 2022 16:50:16 +0200 Subject: [PATCH] WebDriver: Replace hardcoded timeout with a TimeoutsConfiguration struct --- Userland/Services/WebDriver/Session.cpp | 3 ++- Userland/Services/WebDriver/Session.h | 9 ++++---- .../WebDriver/TimeoutsConfiguration.h | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 Userland/Services/WebDriver/TimeoutsConfiguration.h diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index cc6615bca3..b68cb250f3 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2022, Florent Castelli * Copyright (c) 2022, Sam Atkins * Copyright (c) 2022, Tobias Christiansen + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -265,7 +266,7 @@ static JsonObject web_element_reference_object(Session::LocalElement const& elem ErrorOr Session::find(Session::LocalElement const& start_node, StringView const& using_, StringView const& value) { // 1. Let end time be the current time plus the session implicit wait timeout. - auto end_time = Core::DateTime::from_timestamp(Core::DateTime::now().timestamp() + s_session_timeouts); + auto end_time = Core::DateTime::from_timestamp(Core::DateTime::now().timestamp() + m_timeouts_configuration.implicit_wait_timeout / 1000); // 2. Let location strategy be equal to using. auto location_strategy = using_; diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 84ef798e7f..4ba3efcddd 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Florent Castelli + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,6 +12,7 @@ #include #include #include +#include #include namespace WebDriver { @@ -55,10 +57,6 @@ public: ErrorOr delete_cookie(StringView const& name); ErrorOr delete_all_cookies(); - // https://w3c.github.io/webdriver/#dfn-session-script-timeout - // NOTE: Hardcoded timeouts to 30 seconds. - static int const s_session_timeouts = 30; - private: void delete_cookies(Optional const& name = {}); ErrorOr find(LocalElement const& start_node, StringView const& location_strategy, StringView const& selector); @@ -84,6 +82,9 @@ private: String m_current_window_handle; RefPtr m_local_server; RefPtr m_browser_connection; + + // https://w3c.github.io/webdriver/#dfn-session-script-timeout + TimeoutsConfiguration m_timeouts_configuration; }; } diff --git a/Userland/Services/WebDriver/TimeoutsConfiguration.h b/Userland/Services/WebDriver/TimeoutsConfiguration.h new file mode 100644 index 0000000000..62af89bd3e --- /dev/null +++ b/Userland/Services/WebDriver/TimeoutsConfiguration.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace WebDriver { + +// https://w3c.github.io/webdriver/#dfn-timeouts-configuration +struct TimeoutsConfiguration { + Optional script_timeout { 30'000 }; + u64 page_load_timeout { 300'000 }; + u64 implicit_wait_timeout { 0 }; +}; + +}