mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
Browser+WebContent+WebDriver: Move Find Elements From Element to WC
This also lets us remove the element location strategy and some WebContent IPC from Browser/LibWebView now that they are unused.
This commit is contained in:
parent
5a750dc58c
commit
560da56a1d
16 changed files with 31 additions and 271 deletions
|
@ -468,39 +468,6 @@ void ConnectionFromClient::js_console_request_messages(i32 start_index)
|
|||
m_console_client->send_messages(start_index);
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetDocumentElementResponse ConnectionFromClient::get_document_element()
|
||||
{
|
||||
auto* document = page().top_level_browsing_context().active_document();
|
||||
if (!document)
|
||||
return Optional<i32> {};
|
||||
return { document->id() };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::QuerySelectorAllResponse ConnectionFromClient::query_selector_all(i32 start_node_id, String const& selector)
|
||||
{
|
||||
auto* start_node = Web::DOM::Node::from_id(start_node_id);
|
||||
if (!start_node)
|
||||
return Optional<Vector<i32>> {};
|
||||
|
||||
if (!start_node->is_element() && !start_node->is_document())
|
||||
return Optional<Vector<i32>> {};
|
||||
|
||||
auto& start_element = verify_cast<Web::DOM::ParentNode>(*start_node);
|
||||
|
||||
auto result = start_element.query_selector_all(selector);
|
||||
if (result.is_error())
|
||||
return Optional<Vector<i32>> {};
|
||||
|
||||
auto element_list = result.release_value();
|
||||
Vector<i32> return_list;
|
||||
for (u32 i = 0; i < element_list->length(); i++) {
|
||||
auto node = element_list->item(i);
|
||||
return_list.append(node->id());
|
||||
}
|
||||
|
||||
return { return_list };
|
||||
}
|
||||
|
||||
static Optional<Web::DOM::Element&> find_element_by_id(i32 element_id)
|
||||
{
|
||||
auto* node = Web::DOM::Node::from_id(element_id);
|
||||
|
|
|
@ -83,8 +83,6 @@ private:
|
|||
virtual void run_javascript(String const&) override;
|
||||
virtual void js_console_request_messages(i32) override;
|
||||
|
||||
virtual Messages::WebContentServer::GetDocumentElementResponse get_document_element() override;
|
||||
virtual Messages::WebContentServer::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override;
|
||||
virtual void scroll_element_into_view(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::IsElementSelectedResponse is_element_selected(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetElementAttributeResponse get_element_attribute(i32 element_id, String const& name) override;
|
||||
|
|
|
@ -42,8 +42,6 @@ endpoint WebContentServer
|
|||
js_console_input(String js_source) =|
|
||||
js_console_request_messages(i32 start_index) =|
|
||||
|
||||
get_document_element() => (Optional<i32> node_id)
|
||||
query_selector_all(i32 start_node_id, String selector) => (Optional<Vector<i32>> elements_ids)
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
is_element_selected(i32 element_id) => (bool selected)
|
||||
get_element_attribute(i32 element_id, String name) => (Optional<String> attribute)
|
||||
|
|
|
@ -12,4 +12,5 @@ endpoint WebDriverClient {
|
|||
find_element(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
find_elements(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
find_element_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)
|
||||
find_elements_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -427,6 +427,34 @@ Messages::WebDriverClient::FindElementFromElementResponse WebDriverConnection::f
|
|||
return make_success_response(result.at(0));
|
||||
}
|
||||
|
||||
// 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element
|
||||
Messages::WebDriverClient::FindElementsFromElementResponse WebDriverConnection::find_elements_from_element(JsonValue const& payload, String const& element_id)
|
||||
{
|
||||
// 1. Let location strategy be the result of getting a property called "using".
|
||||
auto location_strategy_string = TRY(get_property(payload, "using"sv));
|
||||
auto location_strategy = Web::WebDriver::location_strategy_from_string(location_strategy_string);
|
||||
|
||||
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
|
||||
if (!location_strategy.has_value())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, String::formatted("Location strategy '{}' is invalid", location_strategy_string));
|
||||
|
||||
// 3. Let selector be the result of getting a property called "value".
|
||||
// 4. If selector is undefined, return error with error code invalid argument.
|
||||
auto selector = TRY(get_property(payload, "value"sv));
|
||||
|
||||
// 5. If the current browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// FIXME: 6. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 7. Let start node be the result of trying to get a known connected element with url variable element id.
|
||||
auto* start_node = TRY(get_known_connected_element(element_id));
|
||||
|
||||
// 8. Return the result of trying to Find with start node, location strategy, and selector.
|
||||
auto result = TRY(find(*start_node, *location_strategy, selector));
|
||||
return make_success_response(move(result));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
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;
|
||||
|
||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||
void restore_the_window();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue