2022-11-08 10:03:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
|
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
|
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2022-11-10 20:55:17 -05:00
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
#include <LibJS/Heap/MarkedVector.h>
|
2022-11-09 15:02:38 -05:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
#include <LibWeb/WebDriver/ElementLocationStrategies.h>
|
2022-11-08 10:03:07 -05:00
|
|
|
#include <LibWeb/WebDriver/Response.h>
|
|
|
|
#include <WebContent/Forward.h>
|
|
|
|
#include <WebContent/WebDriverClientEndpoint.h>
|
|
|
|
#include <WebContent/WebDriverServerEndpoint.h>
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
|
|
class WebDriverConnection final
|
|
|
|
: public IPC::ConnectionToServer<WebDriverClientEndpoint, WebDriverServerEndpoint> {
|
|
|
|
C_OBJECT_ABSTRACT(WebDriverConnection)
|
|
|
|
|
|
|
|
public:
|
2022-11-09 09:56:20 -05:00
|
|
|
static ErrorOr<NonnullRefPtr<WebDriverConnection>> connect(ConnectionFromClient& web_content_client, PageHost& page_host, String const& webdriver_ipc_path);
|
2022-11-08 10:03:07 -05:00
|
|
|
virtual ~WebDriverConnection() = default;
|
|
|
|
|
|
|
|
private:
|
2022-11-09 09:56:20 -05:00
|
|
|
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, ConnectionFromClient& web_content_client, PageHost& page_host);
|
2022-11-08 10:03:07 -05:00
|
|
|
|
|
|
|
virtual void die() override { }
|
2022-11-08 14:14:29 -05:00
|
|
|
|
|
|
|
virtual void close_session() override;
|
2022-11-08 10:42:12 -05:00
|
|
|
virtual void set_is_webdriver_active(bool) override;
|
2022-11-08 12:58:24 -05:00
|
|
|
virtual Messages::WebDriverClient::NavigateToResponse navigate_to(JsonValue const& payload) override;
|
2022-11-08 13:06:22 -05:00
|
|
|
virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override;
|
2022-11-09 09:56:20 -05:00
|
|
|
virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override;
|
|
|
|
virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override;
|
2022-11-09 11:00:53 -05:00
|
|
|
virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override;
|
|
|
|
virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override;
|
2022-11-09 15:02:38 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementResponse find_element(JsonValue const& payload) override;
|
2022-11-09 15:08:49 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override;
|
2022-11-09 15:18:28 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override;
|
2022-11-09 15:25:23 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementsFromElementResponse find_elements_from_element(JsonValue const& payload, String const& element_id) override;
|
2022-11-10 08:15:39 -05:00
|
|
|
virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override;
|
2022-11-10 08:57:37 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override;
|
2022-11-10 09:25:53 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override;
|
2022-11-10 10:11:04 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(String const& element_id, String const& name) override;
|
2022-11-10 10:21:03 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override;
|
2022-11-10 10:24:49 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
|
2022-11-10 10:33:29 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override;
|
2022-11-10 10:39:09 -05:00
|
|
|
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override;
|
2022-11-10 18:00:01 -05:00
|
|
|
virtual Messages::WebDriverClient::GetSourceResponse get_source() override;
|
2022-11-10 20:55:17 -05:00
|
|
|
virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override;
|
2022-11-10 21:00:27 -05:00
|
|
|
virtual Messages::WebDriverClient::ExecuteAsyncScriptResponse execute_async_script(JsonValue const& payload) override;
|
2022-11-11 09:24:07 -05:00
|
|
|
virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override;
|
2022-11-11 09:55:11 -05:00
|
|
|
virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
2022-11-11 11:00:45 -05:00
|
|
|
virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override;
|
2022-11-10 13:20:44 -05:00
|
|
|
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
2022-11-10 13:33:18 -05:00
|
|
|
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
2022-11-08 12:58:24 -05:00
|
|
|
|
|
|
|
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
2022-11-09 09:56:20 -05:00
|
|
|
void restore_the_window();
|
2022-11-09 11:00:53 -05:00
|
|
|
Gfx::IntRect maximize_the_window();
|
|
|
|
Gfx::IntRect iconify_the_window();
|
2022-11-09 15:02:38 -05:00
|
|
|
ErrorOr<JsonArray, Web::WebDriver::Error> find(Web::DOM::ParentNode& start_node, Web::WebDriver::LocationStrategy using_, StringView value);
|
2022-11-08 10:03:07 -05:00
|
|
|
|
2022-11-10 20:55:17 -05:00
|
|
|
struct ScriptArguments {
|
|
|
|
String script;
|
|
|
|
JS::MarkedVector<JS::Value> arguments;
|
|
|
|
};
|
|
|
|
ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JsonValue const& payload);
|
|
|
|
|
2022-11-09 09:56:20 -05:00
|
|
|
ConnectionFromClient& m_web_content_client;
|
2022-11-08 10:03:07 -05:00
|
|
|
PageHost& m_page_host;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|