2022-10-12 10:14:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
|
2022-10-19 15:46:31 +00:00
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2022-11-03 17:31:08 +00:00
|
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
2022-10-12 10:14:59 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-15 13:46:01 +00:00
|
|
|
#include <AK/Function.h>
|
2023-03-07 15:36:39 +00:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2023-08-06 16:09:39 +00:00
|
|
|
#include <LibCore/EventReceiver.h>
|
2022-11-13 04:37:58 +00:00
|
|
|
#include <LibWeb/WebDriver/Client.h>
|
2022-11-08 15:10:27 +00:00
|
|
|
#include <LibWeb/WebDriver/Error.h>
|
2022-11-08 14:42:36 +00:00
|
|
|
#include <LibWeb/WebDriver/Response.h>
|
2022-10-12 10:14:59 +00:00
|
|
|
#include <WebDriver/Session.h>
|
|
|
|
|
|
|
|
namespace WebDriver {
|
|
|
|
|
2022-12-15 13:46:01 +00:00
|
|
|
struct LaunchBrowserCallbacks {
|
2023-12-16 14:19:34 +00:00
|
|
|
Function<ErrorOr<pid_t>(ByteString const&)> launch_browser;
|
|
|
|
Function<ErrorOr<pid_t>(ByteString const&)> launch_headless_browser;
|
2022-12-15 13:46:01 +00:00
|
|
|
};
|
|
|
|
|
2022-11-13 04:37:58 +00:00
|
|
|
class Client final : public Web::WebDriver::Client {
|
|
|
|
C_OBJECT_ABSTRACT(Client);
|
2022-10-12 10:14:59 +00:00
|
|
|
|
|
|
|
public:
|
2023-08-06 16:09:39 +00:00
|
|
|
static ErrorOr<NonnullRefPtr<Client>> try_create(NonnullOwnPtr<Core::BufferedTCPSocket>, LaunchBrowserCallbacks, Core::EventReceiver* parent);
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual ~Client() override;
|
|
|
|
|
2022-10-12 10:14:59 +00:00
|
|
|
void close_session(unsigned session_id);
|
|
|
|
|
|
|
|
private:
|
2023-08-06 16:09:39 +00:00
|
|
|
Client(NonnullOwnPtr<Core::BufferedTCPSocket>, LaunchBrowserCallbacks, Core::EventReceiver* parent);
|
2022-10-12 10:14:59 +00:00
|
|
|
|
2023-03-07 15:36:39 +00:00
|
|
|
ErrorOr<NonnullRefPtr<Session>, Web::WebDriver::Error> find_session_with_id(StringView session_id);
|
2022-10-12 10:14:59 +00:00
|
|
|
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response new_session(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response delete_session(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_status(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_timeouts(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response set_timeouts(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response navigate_to(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_current_url(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response back(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response forward(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response refresh(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_title(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_window_handle(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response close_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-25 02:32:53 +00:00
|
|
|
virtual Web::WebDriver::Response switch_to_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response get_window_handles(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2023-03-14 11:09:50 +00:00
|
|
|
virtual Web::WebDriver::Response new_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response get_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response set_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response maximize_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response minimize_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response fullscreen_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2024-05-29 17:14:42 +00:00
|
|
|
virtual Web::WebDriver::Response consume_user_activation(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response find_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response find_elements(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response find_element_from_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response find_elements_from_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-15 00:48:48 +00:00
|
|
|
virtual Web::WebDriver::Response find_element_from_shadow_root(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-15 00:54:17 +00:00
|
|
|
virtual Web::WebDriver::Response find_elements_from_shadow_root(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-15 00:02:23 +00:00
|
|
|
virtual Web::WebDriver::Response get_active_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-15 00:27:11 +00:00
|
|
|
virtual Web::WebDriver::Response get_element_shadow_root(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response is_element_selected(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_attribute(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_property(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_css_value(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_text(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_tag_name(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_element_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response is_element_enabled(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2023-01-15 16:26:08 +00:00
|
|
|
virtual Web::WebDriver::Response get_computed_role(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2023-02-19 17:36:08 +00:00
|
|
|
virtual Web::WebDriver::Response get_computed_label(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2023-01-26 14:11:54 +00:00
|
|
|
virtual Web::WebDriver::Response element_click(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response get_source(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response execute_script(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response execute_async_script(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_all_cookies(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response get_named_cookie(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response add_cookie(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response delete_cookie(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response delete_all_cookies(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2023-06-17 15:36:00 +00:00
|
|
|
virtual Web::WebDriver::Response release_actions(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-16 12:15:57 +00:00
|
|
|
virtual Web::WebDriver::Response dismiss_alert(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-16 12:24:22 +00:00
|
|
|
virtual Web::WebDriver::Response accept_alert(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-16 13:26:48 +00:00
|
|
|
virtual Web::WebDriver::Response get_alert_text(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-16 13:57:05 +00:00
|
|
|
virtual Web::WebDriver::Response send_alert_text(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-13 04:37:58 +00:00
|
|
|
virtual Web::WebDriver::Response take_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
|
|
|
virtual Web::WebDriver::Response take_element_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-11-26 23:30:03 +00:00
|
|
|
virtual Web::WebDriver::Response print_page(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
2022-10-12 10:14:59 +00:00
|
|
|
|
2023-03-07 15:36:39 +00:00
|
|
|
static HashMap<unsigned, NonnullRefPtr<Session>> s_sessions;
|
2022-10-12 10:14:59 +00:00
|
|
|
static Atomic<unsigned> s_next_session_id;
|
2022-12-15 13:46:01 +00:00
|
|
|
|
|
|
|
LaunchBrowserCallbacks m_callbacks;
|
2022-10-12 10:14:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|