mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb+WebContent+WebDriver: Implement Get Alert Text
This commit is contained in:
parent
3e7d633954
commit
f9b8742fff
Notes:
sideshowbarker
2024-07-17 07:11:12 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/f9b8742fff Pull-request: https://github.com/SerenityOS/serenity/pull/16091 Reviewed-by: https://github.com/linusg
9 changed files with 47 additions and 0 deletions
|
@ -95,6 +95,7 @@ static constexpr auto s_webdriver_endpoints = Array {
|
|||
ROUTE(DELETE, "/session/:session_id/cookie"sv, delete_all_cookies),
|
||||
ROUTE(POST, "/session/:session_id/alert/dismiss"sv, dismiss_alert),
|
||||
ROUTE(POST, "/session/:session_id/alert/accept"sv, accept_alert),
|
||||
ROUTE(GET, "/session/:session_id/alert/text"sv, get_alert_text),
|
||||
ROUTE(GET, "/session/:session_id/screenshot"sv, take_screenshot),
|
||||
ROUTE(GET, "/session/:session_id/element/:element_id/screenshot"sv, take_element_screenshot),
|
||||
};
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
// 16. User prompts, https://w3c.github.io/webdriver/#user-prompts
|
||||
virtual Response dismiss_alert(Parameters parameters, JsonValue payload) = 0;
|
||||
virtual Response accept_alert(Parameters parameters, JsonValue payload) = 0;
|
||||
virtual Response get_alert_text(Parameters parameters, JsonValue payload) = 0;
|
||||
|
||||
// 17. Screen capture, https://w3c.github.io/webdriver/#screen-capture
|
||||
virtual Response take_screenshot(Parameters parameters, JsonValue payload) = 0;
|
||||
|
|
|
@ -262,6 +262,9 @@ void PageHost::page_did_request_alert(String const& message)
|
|||
m_pending_dialog = PendingDialog::Alert;
|
||||
m_client.async_did_request_alert(message);
|
||||
|
||||
if (!message.is_empty())
|
||||
m_pending_dialog_text = message;
|
||||
|
||||
spin_event_loop_until_dialog_closed(m_client, m_pending_alert_response);
|
||||
}
|
||||
|
||||
|
@ -270,6 +273,7 @@ void PageHost::alert_closed()
|
|||
if (m_pending_dialog == PendingDialog::Alert) {
|
||||
m_pending_dialog = PendingDialog::None;
|
||||
m_pending_alert_response = Empty {};
|
||||
m_pending_dialog_text.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,6 +282,9 @@ bool PageHost::page_did_request_confirm(String const& message)
|
|||
m_pending_dialog = PendingDialog::Confirm;
|
||||
m_client.async_did_request_confirm(message);
|
||||
|
||||
if (!message.is_empty())
|
||||
m_pending_dialog_text = message;
|
||||
|
||||
return spin_event_loop_until_dialog_closed(m_client, m_pending_confirm_response);
|
||||
}
|
||||
|
||||
|
@ -286,6 +293,7 @@ void PageHost::confirm_closed(bool accepted)
|
|||
if (m_pending_dialog == PendingDialog::Confirm) {
|
||||
m_pending_dialog = PendingDialog::None;
|
||||
m_pending_confirm_response = accepted;
|
||||
m_pending_dialog_text.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,6 +302,9 @@ String PageHost::page_did_request_prompt(String const& message, String const& de
|
|||
m_pending_dialog = PendingDialog::Prompt;
|
||||
m_client.async_did_request_prompt(message, default_);
|
||||
|
||||
if (!message.is_empty())
|
||||
m_pending_dialog_text = message;
|
||||
|
||||
return spin_event_loop_until_dialog_closed(m_client, m_pending_prompt_response);
|
||||
}
|
||||
|
||||
|
@ -302,6 +313,7 @@ void PageHost::prompt_closed(String response)
|
|||
if (m_pending_dialog == PendingDialog::Prompt) {
|
||||
m_pending_dialog = PendingDialog::None;
|
||||
m_pending_prompt_response = move(response);
|
||||
m_pending_dialog_text.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
};
|
||||
bool has_pending_dialog() const { return m_pending_dialog != PendingDialog::None; }
|
||||
PendingDialog pending_dialog() const { return m_pending_dialog; }
|
||||
Optional<String> const& pending_dialog_text() const { return m_pending_dialog_text; }
|
||||
void dismiss_dialog();
|
||||
void accept_dialog();
|
||||
|
||||
|
@ -112,6 +113,7 @@ private:
|
|||
RefPtr<WebDriverConnection> m_webdriver;
|
||||
|
||||
PendingDialog m_pending_dialog { PendingDialog::None };
|
||||
Optional<String> m_pending_dialog_text;
|
||||
Optional<Empty> m_pending_alert_response;
|
||||
Optional<bool> m_pending_confirm_response;
|
||||
Optional<String> m_pending_prompt_response;
|
||||
|
|
|
@ -45,6 +45,7 @@ endpoint WebDriverClient {
|
|||
delete_all_cookies() => (Web::WebDriver::Response response)
|
||||
dismiss_alert() => (Web::WebDriver::Response response)
|
||||
accept_alert() => (Web::WebDriver::Response response)
|
||||
get_alert_text() => (Web::WebDriver::Response response)
|
||||
take_screenshot() => (Web::WebDriver::Response response)
|
||||
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -1377,6 +1377,25 @@ Messages::WebDriverClient::AcceptAlertResponse WebDriverConnection::accept_alert
|
|||
return JsonValue {};
|
||||
}
|
||||
|
||||
// 16.3 Get Alert Text, https://w3c.github.io/webdriver/#get-alert-text
|
||||
Messages::WebDriverClient::GetAlertTextResponse WebDriverConnection::get_alert_text()
|
||||
{
|
||||
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// 2. If there is no current user prompt, return error with error code no such alert.
|
||||
if (!m_page_host.has_pending_dialog())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchAlert, "No user dialog is currently open"sv);
|
||||
|
||||
// 3. Let message be the text message associated with the current user prompt, or otherwise be null.
|
||||
auto const& message = m_page_host.pending_dialog_text();
|
||||
|
||||
// 4. Return success with data message.
|
||||
if (message.has_value())
|
||||
return *message;
|
||||
return JsonValue {};
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
|
||||
{
|
||||
|
|
|
@ -80,6 +80,7 @@ private:
|
|||
virtual Messages::WebDriverClient::DeleteAllCookiesResponse delete_all_cookies() override;
|
||||
virtual Messages::WebDriverClient::DismissAlertResponse dismiss_alert() override;
|
||||
virtual Messages::WebDriverClient::AcceptAlertResponse accept_alert() override;
|
||||
virtual Messages::WebDriverClient::GetAlertTextResponse get_alert_text() override;
|
||||
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
||||
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
||||
|
||||
|
|
|
@ -557,6 +557,15 @@ Web::WebDriver::Response Client::accept_alert(Web::WebDriver::Parameters paramet
|
|||
return session->web_content_connection().accept_alert();
|
||||
}
|
||||
|
||||
// 16.3 Get Alert Text, https://w3c.github.io/webdriver/#get-alert-text
|
||||
// GET /session/{session id}/alert/text
|
||||
Web::WebDriver::Response Client::get_alert_text(Web::WebDriver::Parameters parameters, JsonValue)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/alert/text");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
return session->web_content_connection().get_alert_text();
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
// GET /session/{session id}/screenshot
|
||||
Web::WebDriver::Response Client::take_screenshot(Web::WebDriver::Parameters parameters, JsonValue)
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
virtual Web::WebDriver::Response delete_all_cookies(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response dismiss_alert(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response accept_alert(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response get_alert_text(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response take_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response take_element_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue