/* * Copyright (c) 2022, Florent Castelli * Copyright (c) 2022, Linus Groh * Copyright (c) 2022-2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace WebContent { class WebDriverConnection final : public IPC::ConnectionToServer { C_OBJECT_ABSTRACT(WebDriverConnection) public: static ErrorOr> connect(Web::PageClient& page_client, DeprecatedString const& webdriver_ipc_path); virtual ~WebDriverConnection() = default; private: WebDriverConnection(NonnullOwnPtr socket, Web::PageClient& page_client); virtual void die() override { } virtual void close_session() override; virtual void set_page_load_strategy(Web::WebDriver::PageLoadStrategy const& page_load_strategy) override; virtual void set_unhandled_prompt_behavior(Web::WebDriver::UnhandledPromptBehavior const& unhandled_prompt_behavior) override; virtual void set_strict_file_interactability(bool strict_file_interactability) override; virtual void set_is_webdriver_active(bool) override; virtual Messages::WebDriverClient::GetTimeoutsResponse get_timeouts() override; virtual Messages::WebDriverClient::SetTimeoutsResponse set_timeouts(JsonValue const& payload) override; virtual Messages::WebDriverClient::NavigateToResponse navigate_to(JsonValue const& payload) override; virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override; virtual Messages::WebDriverClient::BackResponse back() override; virtual Messages::WebDriverClient::ForwardResponse forward() override; virtual Messages::WebDriverClient::RefreshResponse refresh() override; virtual Messages::WebDriverClient::GetTitleResponse get_title() override; virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override; virtual Messages::WebDriverClient::CloseWindowResponse close_window() override; virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window() override; virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) override; virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override; virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override; virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override; virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override; virtual Messages::WebDriverClient::FullscreenWindowResponse fullscreen_window() override; virtual Messages::WebDriverClient::FindElementResponse find_element(JsonValue const& payload) override; virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override; virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override; virtual Messages::WebDriverClient::FindElementsFromElementResponse find_elements_from_element(JsonValue const& payload, String const& element_id) override; virtual Messages::WebDriverClient::FindElementFromShadowRootResponse find_element_from_shadow_root(JsonValue const& payload, String const& shadow_id) override; virtual Messages::WebDriverClient::FindElementsFromShadowRootResponse find_elements_from_shadow_root(JsonValue const& payload, String const& shadow_id) override; virtual Messages::WebDriverClient::GetActiveElementResponse get_active_element() override; virtual Messages::WebDriverClient::GetElementShadowRootResponse get_element_shadow_root(String const& element_id) override; virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override; virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override; virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override; virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(String const& element_id, String const& name) override; virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override; virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override; virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override; virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override; virtual Messages::WebDriverClient::GetComputedRoleResponse get_computed_role(String const& element_id) override; virtual Messages::WebDriverClient::GetComputedLabelResponse get_computed_label(String const& element_id) override; virtual Messages::WebDriverClient::ElementClickResponse element_click(String const& element_id) override; virtual Messages::WebDriverClient::GetSourceResponse get_source() override; virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override; virtual Messages::WebDriverClient::ExecuteAsyncScriptResponse execute_async_script(JsonValue const& payload) override; virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override; virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override; virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override; virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override; virtual Messages::WebDriverClient::DeleteAllCookiesResponse delete_all_cookies() override; virtual Messages::WebDriverClient::DismissAlertResponse dismiss_alert() override; virtual Messages::WebDriverClient::AcceptAlertResponse accept_alert() override; virtual Messages::WebDriverClient::GetAlertTextResponse get_alert_text() override; virtual Messages::WebDriverClient::SendAlertTextResponse send_alert_text(JsonValue const& payload) override; virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override; virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override; virtual Messages::WebDriverClient::PrintPageResponse print_page() override; virtual Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse ensure_top_level_browsing_context_is_open() override; ErrorOr ensure_open_top_level_browsing_context(); ErrorOr handle_any_user_prompts(); void restore_the_window(); Gfx::IntRect maximize_the_window(); Gfx::IntRect iconify_the_window(); ErrorOr wait_for_navigation_to_complete(); using StartNodeGetter = Function()>; ErrorOr find(StartNodeGetter&& start_node_getter, Web::WebDriver::LocationStrategy using_, StringView value); struct ScriptArguments { DeprecatedString script; JS::MarkedVector arguments; }; ErrorOr extract_the_script_arguments_from_a_request(JsonValue const& payload); void delete_cookies(Optional const& name = {}); Web::PageClient& m_page_client; // https://w3c.github.io/webdriver/#dfn-page-load-strategy Web::WebDriver::PageLoadStrategy m_page_load_strategy { Web::WebDriver::PageLoadStrategy::Normal }; // https://w3c.github.io/webdriver/#dfn-unhandled-prompt-behavior Web::WebDriver::UnhandledPromptBehavior m_unhandled_prompt_behavior { Web::WebDriver::UnhandledPromptBehavior::DismissAndNotify }; // https://w3c.github.io/webdriver/#dfn-strict-file-interactability bool m_strict_file_interactability { false }; // https://w3c.github.io/webdriver/#dfn-session-script-timeout Web::WebDriver::TimeoutsConfiguration m_timeouts_configuration; }; }