mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
WebDriver: Add POST /session/{id}/element
endpoint
This allows you to query for elements in the active document! The IDs of matching elements are returned through the WebDriver interface, for now there's nothing to do with this information. This introduces a `LocalElement` to the Session, which for now only holds the ID of a real browser-side element. Once more data of elements are available to the Session, they can be stored alongside in this struct. Fixme's introduced are: - Only CSS selector location strategy is implemented for now - `get_or_create_a_web_element_reference` returns the elements ID instead of a UUID generated in a spec way.
This commit is contained in:
parent
5d762bd448
commit
5fcf00f30d
4 changed files with 221 additions and 0 deletions
|
@ -27,6 +27,10 @@ public:
|
|||
bool is_open;
|
||||
};
|
||||
|
||||
struct LocalElement {
|
||||
i32 id;
|
||||
};
|
||||
|
||||
HashMap<String, NonnullOwnPtr<Window>>& get_window_handles() { return m_windows; }
|
||||
Optional<Window*> get_window_object() { return m_windows.get(m_current_window_handle); }
|
||||
String get_window() { return m_current_window_handle; }
|
||||
|
@ -39,6 +43,7 @@ public:
|
|||
ErrorOr<JsonValue, HttpError> forward();
|
||||
ErrorOr<JsonValue, HttpError> refresh();
|
||||
ErrorOr<JsonValue, HttpError> get_title();
|
||||
ErrorOr<JsonValue, HttpError> find_element(JsonValue const& payload);
|
||||
ErrorOr<void, Variant<HttpError, Error>> delete_window();
|
||||
ErrorOr<JsonValue, HttpError> get_all_cookies();
|
||||
ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name);
|
||||
|
@ -46,8 +51,27 @@ public:
|
|||
ErrorOr<JsonValue, HttpError> delete_cookie(StringView const& name);
|
||||
ErrorOr<JsonValue, HttpError> delete_all_cookies();
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-session-script-timeout
|
||||
// NOTE: Hardcoded timeouts to 30 seconds.
|
||||
static int const s_session_timeouts = 30;
|
||||
|
||||
private:
|
||||
void delete_cookies(Optional<StringView> const& name = {});
|
||||
ErrorOr<JsonArray, HttpError> find(LocalElement const& start_node, StringView const& location_strategy, StringView const& selector);
|
||||
|
||||
using ElementLocationStrategyHandler = ErrorOr<Vector<LocalElement>, HttpError> (Session::*)(LocalElement const&, StringView const&);
|
||||
struct LocatorStrategy {
|
||||
String name;
|
||||
ElementLocationStrategyHandler handler;
|
||||
};
|
||||
|
||||
static Vector<LocatorStrategy> s_locator_strategies;
|
||||
|
||||
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_css_selectors(LocalElement const&, StringView const&);
|
||||
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_link_text(LocalElement const&, StringView const&);
|
||||
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_partial_link_text(LocalElement const&, StringView const&);
|
||||
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_tag_name(LocalElement const&, StringView const&);
|
||||
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_x_path(LocalElement const&, StringView const&);
|
||||
|
||||
NonnullRefPtr<Client> m_client;
|
||||
bool m_started { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue