mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 06:37:35 +00:00
WebDriver+Browser: Implement GET /session/{id}/element/{id}/selected
This commit is contained in:
parent
4067138702
commit
2d75229192
9 changed files with 55 additions and 0 deletions
|
@ -45,6 +45,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "elements" }, &Client::handle_find_elements },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element", ":element_id", "element" }, &Client::handle_find_element_from_element },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element", ":element_id", "elements" }, &Client::handle_find_elements_from_element },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "selected" }, &Client::handle_is_element_selected },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "attribute", ":name" }, &Client::handle_get_element_attribute },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "property", ":name" }, &Client::handle_get_element_property },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "element", ":element_id", "css", ":property_name" }, &Client::handle_get_element_css_value },
|
||||
|
@ -641,6 +642,16 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements_from_element(Vec
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected
|
||||
// GET /session/{session id}/element/{element id}/selected
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/selected");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->is_element_selected(parameters[1]));
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
|
||||
// GET /session/{session id}/element/{element id}/attribute/{name}
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_attribute(Vector<StringView> const& parameters, JsonValue const& payload)
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
ErrorOr<JsonValue, WebDriverError> handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_find_elements_from_element(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_is_element_selected(Vector<StringView> const& parameters, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_element_attribute(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_element_property(Vector<StringView> const&, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> handle_get_element_css_value(Vector<StringView> const&, JsonValue const& payload);
|
||||
|
|
|
@ -758,6 +758,30 @@ ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue
|
|||
return JsonValue(result);
|
||||
}
|
||||
|
||||
// 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected
|
||||
ErrorOr<JsonValue, WebDriverError> Session::is_element_selected(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 selected be the value corresponding to the first matching statement:
|
||||
// element is an input element with a type attribute in the Checkbox- or Radio Button state
|
||||
// -> The result of element’s checkedness.
|
||||
// element is an option element
|
||||
// -> The result of element’s selectedness.
|
||||
// Otherwise
|
||||
// -> False.
|
||||
auto selected = m_browser_connection->is_element_selected(element_id);
|
||||
|
||||
// 5. Return success with data selected.
|
||||
return selected;
|
||||
}
|
||||
|
||||
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
|
||||
ErrorOr<JsonValue, WebDriverError> Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name)
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
ErrorOr<JsonValue, WebDriverError> find_elements(JsonValue const& payload);
|
||||
ErrorOr<JsonValue, WebDriverError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);
|
||||
ErrorOr<JsonValue, WebDriverError> find_elements_from_element(JsonValue const& payload, StringView parameter_element_id);
|
||||
ErrorOr<JsonValue, WebDriverError> is_element_selected(StringView element_id);
|
||||
ErrorOr<JsonValue, WebDriverError> get_element_attribute(JsonValue const& payload, StringView element_id, StringView name);
|
||||
ErrorOr<JsonValue, WebDriverError> get_element_property(JsonValue const& payload, StringView element_id, StringView name);
|
||||
ErrorOr<JsonValue, WebDriverError> get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue