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.
This commit is contained in:
Baitinq 2022-12-24 02:17:06 +01:00 committed by Andreas Kling
parent 6a72a4df96
commit 419dea0996
Notes: sideshowbarker 2024-07-17 07:06:47 +09:00
7 changed files with 58 additions and 0 deletions

View File

@ -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),

View File

@ -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;

View File

@ -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)

View File

@ -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 elements 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 elements container.
auto scroll_or_error = scroll_element_into_view(*element);
// 6. If elements 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, "Elements container is still not in view after scrolling"sv);
// FIXME: 7. If elements 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()
{

View File

@ -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;

View File

@ -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)

View File

@ -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;