mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Browser+WebContent+WebDriver: Move Get Element Tag Name to WebContent
This commit is contained in:
parent
5d32fd7026
commit
9dd62228c8
16 changed files with 22 additions and 57 deletions
|
@ -611,10 +611,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
active_tab().view().scroll_element_into_view(element_id);
|
active_tab().view().scroll_element_into_view(element_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.webdriver_endpoints().on_get_element_tag_name = [this](i32 element_id) {
|
|
||||||
return active_tab().view().get_element_tag_name(element_id);
|
|
||||||
};
|
|
||||||
|
|
||||||
new_tab.webdriver_endpoints().on_get_element_rect = [this](i32 element_id) {
|
new_tab.webdriver_endpoints().on_get_element_rect = [this](i32 element_id) {
|
||||||
return active_tab().view().get_element_rect(element_id);
|
return active_tab().view().get_element_rect(element_id);
|
||||||
};
|
};
|
||||||
|
|
|
@ -146,17 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::WebDriverSessionClient::GetElementTagNameResponse WebDriverConnection::get_element_tag_name(i32 element_id)
|
|
||||||
{
|
|
||||||
dbgln("WebDriverConnection: get_computed_value_for_element");
|
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
|
||||||
auto& tab = browser_window->active_tab();
|
|
||||||
if (tab.webdriver_endpoints().on_get_element_tag_name)
|
|
||||||
return { tab.webdriver_endpoints().on_get_element_tag_name(element_id) };
|
|
||||||
}
|
|
||||||
return { "" };
|
|
||||||
}
|
|
||||||
|
|
||||||
Messages::WebDriverSessionClient::GetElementRectResponse WebDriverConnection::get_element_rect(i32 element_id)
|
Messages::WebDriverSessionClient::GetElementRectResponse WebDriverConnection::get_element_rect(i32 element_id)
|
||||||
{
|
{
|
||||||
dbgln("WebDriverConnection: get_element_rect {}", element_id);
|
dbgln("WebDriverConnection: get_element_rect {}", element_id);
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
||||||
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
||||||
virtual void scroll_element_into_view(i32 element_id) override;
|
virtual void scroll_element_into_view(i32 element_id) override;
|
||||||
virtual Messages::WebDriverSessionClient::GetElementTagNameResponse get_element_tag_name(i32 element_id) override;
|
|
||||||
virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override;
|
virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override;
|
||||||
virtual Messages::WebDriverSessionClient::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
|
virtual Messages::WebDriverSessionClient::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
|
||||||
virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override;
|
virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override;
|
||||||
|
|
|
@ -24,7 +24,6 @@ public:
|
||||||
~WebDriverEndpoints() = default;
|
~WebDriverEndpoints() = default;
|
||||||
|
|
||||||
Function<void(i32 element_id)> on_scroll_element_into_view;
|
Function<void(i32 element_id)> on_scroll_element_into_view;
|
||||||
Function<String(i32 element_id)> on_get_element_tag_name;
|
|
||||||
Function<Gfx::IntRect(i32 element_id)> on_get_element_rect;
|
Function<Gfx::IntRect(i32 element_id)> on_get_element_rect;
|
||||||
Function<bool(i32 element_id)> on_is_element_enabled;
|
Function<bool(i32 element_id)> on_is_element_enabled;
|
||||||
Function<Gfx::ShareableBitmap(i32 element_id)> on_take_element_screenshot;
|
Function<Gfx::ShareableBitmap(i32 element_id)> on_take_element_screenshot;
|
||||||
|
|
|
@ -25,7 +25,6 @@ endpoint WebDriverSessionClient {
|
||||||
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
||||||
update_cookie(Web::Cookie::Cookie cookie) =|
|
update_cookie(Web::Cookie::Cookie cookie) =|
|
||||||
scroll_element_into_view(i32 element_id) => ()
|
scroll_element_into_view(i32 element_id) => ()
|
||||||
get_element_tag_name(i32 element_id) => (String tag_name)
|
|
||||||
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
||||||
is_element_enabled(i32 element_id) => (bool enabled)
|
is_element_enabled(i32 element_id) => (bool enabled)
|
||||||
take_screenshot() => (Gfx::ShareableBitmap data)
|
take_screenshot() => (Gfx::ShareableBitmap data)
|
||||||
|
|
|
@ -559,11 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id)
|
||||||
return client().scroll_element_into_view(element_id);
|
return client().scroll_element_into_view(element_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
String OutOfProcessWebView::get_element_tag_name(i32 element_id)
|
|
||||||
{
|
|
||||||
return client().get_element_tag_name(element_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gfx::IntRect OutOfProcessWebView::get_element_rect(i32 element_id)
|
Gfx::IntRect OutOfProcessWebView::get_element_rect(i32 element_id)
|
||||||
{
|
{
|
||||||
return client().get_element_rect(element_id);
|
return client().get_element_rect(element_id);
|
||||||
|
|
|
@ -64,7 +64,6 @@ public:
|
||||||
OrderedHashMap<String, String> get_session_storage_entries();
|
OrderedHashMap<String, String> get_session_storage_entries();
|
||||||
|
|
||||||
void scroll_element_into_view(i32 element_id);
|
void scroll_element_into_view(i32 element_id);
|
||||||
String get_element_tag_name(i32 element_id);
|
|
||||||
Gfx::IntRect get_element_rect(i32 element_id);
|
Gfx::IntRect get_element_rect(i32 element_id);
|
||||||
bool is_element_enabled(i32 element_id);
|
bool is_element_enabled(i32 element_id);
|
||||||
|
|
||||||
|
|
|
@ -494,15 +494,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id)
|
||||||
element->scroll_into_view(options);
|
element->scroll_into_view(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::WebContentServer::GetElementTagNameResponse ConnectionFromClient::get_element_tag_name(i32 element_id)
|
|
||||||
{
|
|
||||||
auto element = find_element_by_id(element_id);
|
|
||||||
if (!element.has_value())
|
|
||||||
return { "" };
|
|
||||||
|
|
||||||
return { element->tag_name() };
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/#dfn-calculate-the-absolute-position
|
// https://w3c.github.io/webdriver/#dfn-calculate-the-absolute-position
|
||||||
static Gfx::IntPoint calculate_absolute_position_of_element(Web::Page const& page, JS::NonnullGCPtr<Web::Geometry::DOMRect> rect)
|
static Gfx::IntPoint calculate_absolute_position_of_element(Web::Page const& page, JS::NonnullGCPtr<Web::Geometry::DOMRect> rect)
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,6 @@ private:
|
||||||
virtual void js_console_request_messages(i32) override;
|
virtual void js_console_request_messages(i32) override;
|
||||||
|
|
||||||
virtual void scroll_element_into_view(i32 element_id) override;
|
virtual void scroll_element_into_view(i32 element_id) override;
|
||||||
virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override;
|
|
||||||
virtual Messages::WebContentServer::GetElementRectResponse get_element_rect(i32 element_id) override;
|
virtual Messages::WebContentServer::GetElementRectResponse get_element_rect(i32 element_id) override;
|
||||||
virtual Messages::WebContentServer::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
|
virtual Messages::WebContentServer::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
|
||||||
virtual Messages::WebContentServer::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
|
virtual Messages::WebContentServer::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
|
||||||
|
|
|
@ -43,7 +43,6 @@ endpoint WebContentServer
|
||||||
js_console_request_messages(i32 start_index) =|
|
js_console_request_messages(i32 start_index) =|
|
||||||
|
|
||||||
scroll_element_into_view(i32 element_id) => ()
|
scroll_element_into_view(i32 element_id) => ()
|
||||||
get_element_tag_name(i32 element_id) => (String tag_name)
|
|
||||||
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
||||||
is_element_enabled(i32 element_id) => (bool enabled)
|
is_element_enabled(i32 element_id) => (bool enabled)
|
||||||
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
|
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
|
||||||
|
|
|
@ -18,4 +18,5 @@ endpoint WebDriverClient {
|
||||||
get_element_property(String element_id, String name) => (Web::WebDriver::Response response)
|
get_element_property(String element_id, String name) => (Web::WebDriver::Response response)
|
||||||
get_element_css_value(String element_id, String name) => (Web::WebDriver::Response response)
|
get_element_css_value(String element_id, String name) => (Web::WebDriver::Response response)
|
||||||
get_element_text(String element_id) => (Web::WebDriver::Response response)
|
get_element_text(String element_id) => (Web::WebDriver::Response response)
|
||||||
|
get_element_tag_name(String element_id) => (Web::WebDriver::Response response)
|
||||||
}
|
}
|
||||||
|
|
|
@ -608,6 +608,24 @@ Messages::WebDriverClient::GetElementTextResponse WebDriverConnection::get_eleme
|
||||||
return make_success_response(move(rendered_text));
|
return make_success_response(move(rendered_text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
|
||||||
|
Messages::WebDriverClient::GetElementTagNameResponse WebDriverConnection::get_element_tag_name(String 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());
|
||||||
|
|
||||||
|
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||||
|
|
||||||
|
// 3. Let element be the result of trying to get a known connected element with url variable element id.
|
||||||
|
auto* element = TRY(get_known_connected_element(element_id));
|
||||||
|
|
||||||
|
// 4. Let qualified name be the result of getting element’s tagName IDL attribute.
|
||||||
|
auto qualified_name = element->tag_name();
|
||||||
|
|
||||||
|
// 5. Return success with data qualified name.
|
||||||
|
return make_success_response(move(qualified_name));
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ private:
|
||||||
virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(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::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::GetElementTextResponse get_element_text(String const& element_id) override;
|
||||||
|
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
|
||||||
|
|
||||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||||
void restore_the_window();
|
void restore_the_window();
|
||||||
|
|
|
@ -695,12 +695,11 @@ Web::WebDriver::Response Client::handle_get_element_text(Vector<StringView> cons
|
||||||
|
|
||||||
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
|
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
|
||||||
// GET /session/{session id}/element/{element id}/name
|
// GET /session/{session id}/element/{element id}/name
|
||||||
Web::WebDriver::Response Client::handle_get_element_tag_name(Vector<StringView> const& parameters, JsonValue const& payload)
|
Web::WebDriver::Response Client::handle_get_element_tag_name(Vector<StringView> const& parameters, JsonValue const&)
|
||||||
{
|
{
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/name");
|
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/name");
|
||||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||||
auto result = TRY(session->get_element_tag_name(payload, parameters[1]));
|
return session->web_content_connection().get_element_tag_name(parameters[1]);
|
||||||
return make_json_value(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
|
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
|
||||||
|
|
|
@ -323,24 +323,6 @@ static ErrorOr<i32, Web::WebDriver::Error> get_known_connected_element(StringVie
|
||||||
return maybe_element_id.release_value();
|
return maybe_element_id.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name
|
|
||||||
Web::WebDriver::Response Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id)
|
|
||||||
{
|
|
||||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
|
||||||
TRY(check_for_open_top_level_browsing_context_or_return_error());
|
|
||||||
|
|
||||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
|
||||||
|
|
||||||
// 3. Let element be the result of trying to get a known connected element with url variable element id.
|
|
||||||
auto element_id = TRY(get_known_connected_element(parameter_element_id));
|
|
||||||
|
|
||||||
// 4. Let qualified name be the result of getting element’s tagName IDL attribute.
|
|
||||||
auto qualified_name = m_browser_connection->get_element_tag_name(element_id);
|
|
||||||
|
|
||||||
// 5. Return success with data qualified name.
|
|
||||||
return JsonValue(qualified_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
|
// 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect
|
||||||
Web::WebDriver::Response Session::get_element_rect(StringView parameter_element_id)
|
Web::WebDriver::Response Session::get_element_rect(StringView parameter_element_id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,7 +58,6 @@ public:
|
||||||
Web::WebDriver::Response get_window_handle();
|
Web::WebDriver::Response get_window_handle();
|
||||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
||||||
Web::WebDriver::Response get_window_handles() const;
|
Web::WebDriver::Response get_window_handles() const;
|
||||||
Web::WebDriver::Response get_element_tag_name(JsonValue const& payload, StringView element_id);
|
|
||||||
Web::WebDriver::Response get_element_rect(StringView element_id);
|
Web::WebDriver::Response get_element_rect(StringView element_id);
|
||||||
Web::WebDriver::Response is_element_enabled(StringView element_id);
|
Web::WebDriver::Response is_element_enabled(StringView element_id);
|
||||||
Web::WebDriver::Response get_source();
|
Web::WebDriver::Response get_source();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue