diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-12-24 02:17:06 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-25 17:24:52 +0100 |
commit | 419dea0996e4f67163188142c4c05819090dd24d (patch) | |
tree | 6e5106210aa794b053767db871da2a2e5a241094 /Userland | |
parent | 6a72a4df963da2fabedef3fc4a88f17b62318290 (diff) | |
download | serenity-419dea0996e4f67163188142c4c05819090dd24d.zip |
WebDriver: Implement stub for .../element/{element id}/click
This patch adds a stub implementation for the POST
/session/{session id}/element/{element id}/click endpoint.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/WebDriver/Client.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebDriver/Client.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 44 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.h | 1 |
7 files changed, 58 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp index 05e1d0564a..69a03277af 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp @@ -86,6 +86,7 @@ static constexpr auto s_webdriver_endpoints = Array { ROUTE(GET, "/session/:session_id/element/:element_id/name"sv, get_element_tag_name), ROUTE(GET, "/session/:session_id/element/:element_id/rect"sv, get_element_rect), ROUTE(GET, "/session/:session_id/element/:element_id/enabled"sv, is_element_enabled), + ROUTE(POST, "/session/:session_id/element/:element_id/click"sv, click), ROUTE(GET, "/session/:session_id/source"sv, get_source), ROUTE(POST, "/session/:session_id/execute/sync"sv, execute_script), ROUTE(POST, "/session/:session_id/execute/async"sv, execute_async_script), diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.h b/Userland/Libraries/LibWeb/WebDriver/Client.h index a282e3cb5e..099c3f63c7 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.h +++ b/Userland/Libraries/LibWeb/WebDriver/Client.h @@ -74,6 +74,7 @@ public: virtual Response get_element_tag_name(Parameters parameters, JsonValue payload) = 0; virtual Response get_element_rect(Parameters parameters, JsonValue payload) = 0; virtual Response is_element_enabled(Parameters parameters, JsonValue payload) = 0; + virtual Response click(Parameters parameters, JsonValue payload) = 0; // 13. Document, https://w3c.github.io/webdriver/#document virtual Response get_source(Parameters parameters, JsonValue payload) = 0; diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index b2ce42909a..277c8e0692 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -40,6 +40,7 @@ endpoint WebDriverClient { get_element_tag_name(DeprecatedString element_id) => (Web::WebDriver::Response response) get_element_rect(DeprecatedString element_id) => (Web::WebDriver::Response response) is_element_enabled(DeprecatedString element_id) => (Web::WebDriver::Response response) + click(DeprecatedString element_id) => (Web::WebDriver::Response response) get_source() => (Web::WebDriver::Response response) execute_script(JsonValue payload) => (Web::WebDriver::Response response) execute_async_script(JsonValue payload) => (Web::WebDriver::Response response) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 50d8f93c37..04a63f1b1b 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1172,6 +1172,50 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem return enabled; } +// 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click +Messages::WebDriverClient::ClickResponse WebDriverConnection::click(DeprecatedString const& element_id) +{ + // 1. If the current browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // 2. Handle any user prompts and return its value if it is an error. + TRY(handle_any_user_prompts()); + + // 3. Let element be the result of trying to get a known element with element id. + auto* element = TRY(get_known_connected_element(element_id)); + + // 4. If the element is an input element in the file upload state return error with error code invalid argument. + if (is<Web::HTML::HTMLInputElement>(*element)) { + // -> The result of element’s checkedness. + auto& input = static_cast<Web::HTML::HTMLInputElement&>(*element); + using enum Web::HTML::HTMLInputElement::TypeAttributeState; + + if (input.type_state() == FileUpload) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Clicking on an input element in the file upload state is not supported"sv); + } + + // 5. Scroll into view the element’s container. + auto scroll_or_error = scroll_element_into_view(*element); + + // 6. If element’s container is still not in view, return error with error code element not interactable. + if (scroll_or_error.is_error()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ElementNotInteractable, "Element’s container is still not in view after scrolling"sv); + + // FIXME: 7. If element’s container is obscured by another element, return error with error code element click intercepted. + + // 8. Matching on element: + // FIXME: option element + // FIXME: Otherwise + + // FIXME: 9. Wait until the user agent event loop has spun enough times to process the DOM events generated by the previous step. + // FIXME: 10. Perform implementation-defined steps to allow any navigations triggered by the click to start. + // FIXME: 11. Try to wait for navigation to complete. + // FIXME: 12. Try to run the post-navigation checks. + // FIXME: 13. Return success with data null. + + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Click not implemented"sv); +} + // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index b3889697c9..4054959430 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -75,6 +75,7 @@ private: virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(DeprecatedString const& element_id) override; virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(DeprecatedString const& element_id) override; virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(DeprecatedString const& element_id) override; + virtual Messages::WebDriverClient::ClickResponse click(DeprecatedString 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; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 85bcd53aa9..84bd7eb426 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -533,6 +533,15 @@ Web::WebDriver::Response Client::is_element_enabled(Web::WebDriver::Parameters p return session->web_content_connection().is_element_enabled(parameters[1]); } +// 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click +// POST /session/{session id}/element/{element id}/click +Web::WebDriver::Response Client::click(Web::WebDriver::Parameters parameters, JsonValue) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element/<element_id>/click"); + auto* session = TRY(find_session_with_id(parameters[0])); + return session->web_content_connection().click(parameters[1]); +} + // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source // GET /session/{session id}/source Web::WebDriver::Response Client::get_source(Web::WebDriver::Parameters parameters, JsonValue) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index bfc1728c42..b30ea1f6c5 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -75,6 +75,7 @@ private: 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; + virtual Web::WebDriver::Response click(Web::WebDriver::Parameters parameters, JsonValue payload) override; 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; |