diff --git a/Source/WebDriver/Capabilities.h b/Source/WebDriver/Capabilities.h index 91a507dabf10..0d37468da597 100644 --- a/Source/WebDriver/Capabilities.h +++ b/Source/WebDriver/Capabilities.h @@ -47,6 +47,8 @@ enum class PageLoadStrategy { enum class UnhandledPromptBehavior { Dismiss, Accept, + DismissAndNotify, + AcceptAndNotify, Ignore }; diff --git a/Source/WebDriver/ChangeLog b/Source/WebDriver/ChangeLog index 0443ed84aecb..5781f5516fb3 100644 --- a/Source/WebDriver/ChangeLog +++ b/Source/WebDriver/ChangeLog @@ -1,3 +1,26 @@ +2017-12-15 Carlos Garcia Campos + + WebDriver: add support for accept/dismiss and notify unhandled prompt behavior + https://bugs.webkit.org/show_bug.cgi?id=179999 + + Reviewed by Carlos Alberto Lopez Perez. + + They work as accept and dismiss, but unexpected alert open is still reported. + + 18. User Prompts + https://w3c.github.io/webdriver/webdriver-spec.html#dfn-known-prompt-handling-approaches-table + + * Capabilities.h: Add DismissAndNotify and AcceptAndNotify to UnhandledPromptBehavior enum. + * Session.cpp: + (WebDriver::Session::handleUnexpectedAlertOpen): Move default implementation to dismissAndNotifyAlert and + acceptAndNotifyAlert and use dismissAndNotifyAlert by default. + (WebDriver::Session::dismissAndNotifyAlert): + (WebDriver::Session::acceptAndNotifyAlert): + * Session.h: + * WebDriverService.cpp: + (WebDriver::deserializeUnhandledPromptBehavior): Handle accept/dismiss and notify. + (WebDriver::WebDriverService::newSession): Ditto. + 2017-12-11 Carlos Garcia Campos WebDriver: get active element should return no such element error when there isn't an active element diff --git a/Source/WebDriver/Session.cpp b/Source/WebDriver/Session.cpp index c564c6e64100..6987672ac792 100644 --- a/Source/WebDriver/Session.cpp +++ b/Source/WebDriver/Session.cpp @@ -190,32 +190,51 @@ void Session::handleUserPrompts(Function&& completionHan void Session::handleUnexpectedAlertOpen(Function&& completionHandler) { - if (!capabilities().unhandledPromptBehavior) { - reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { - dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { - if (result.isError()) { - completionHandler(WTFMove(result)); - return; - } - completionHandler(WTFMove(errorResult)); - }); - }); - return; - } - - switch (capabilities().unhandledPromptBehavior.value()) { + switch (capabilities().unhandledPromptBehavior.value_or(UnhandledPromptBehavior::DismissAndNotify)) { case UnhandledPromptBehavior::Dismiss: dismissAlert(WTFMove(completionHandler)); break; case UnhandledPromptBehavior::Accept: acceptAlert(WTFMove(completionHandler)); break; + case UnhandledPromptBehavior::DismissAndNotify: + dismissAndNotifyAlert(WTFMove(completionHandler)); + break; + case UnhandledPromptBehavior::AcceptAndNotify: + acceptAndNotifyAlert(WTFMove(completionHandler)); + break; case UnhandledPromptBehavior::Ignore: reportUnexpectedAlertOpen(WTFMove(completionHandler)); break; } } +void Session::dismissAndNotifyAlert(Function&& completionHandler) +{ + reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { + dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { + if (result.isError()) { + completionHandler(WTFMove(result)); + return; + } + completionHandler(WTFMove(errorResult)); + }); + }); +} + +void Session::acceptAndNotifyAlert(Function&& completionHandler) +{ + reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { + acceptAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable { + if (result.isError()) { + completionHandler(WTFMove(result)); + return; + } + completionHandler(WTFMove(errorResult)); + }); + }); +} + void Session::reportUnexpectedAlertOpen(Function&& completionHandler) { getAlertText([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) { diff --git a/Source/WebDriver/Session.h b/Source/WebDriver/Session.h index 9418866be387..82a777162056 100644 --- a/Source/WebDriver/Session.h +++ b/Source/WebDriver/Session.h @@ -125,6 +125,8 @@ class Session : public RefCounted { void handleUserPrompts(Function&&); void handleUnexpectedAlertOpen(Function&&); + void dismissAndNotifyAlert(Function&&); + void acceptAndNotifyAlert(Function&&); void reportUnexpectedAlertOpen(Function&&); RefPtr createElement(RefPtr&&); diff --git a/Source/WebDriver/WebDriverService.cpp b/Source/WebDriver/WebDriverService.cpp index 122158490efb..63118cb12e72 100644 --- a/Source/WebDriver/WebDriverService.cpp +++ b/Source/WebDriver/WebDriverService.cpp @@ -313,6 +313,10 @@ static std::optional deserializeUnhandledPromptBehavior return UnhandledPromptBehavior::Dismiss; if (unhandledPromptBehavior == "accept") return UnhandledPromptBehavior::Accept; + if (unhandledPromptBehavior == "dismiss and notify") + return UnhandledPromptBehavior::DismissAndNotify; + if (unhandledPromptBehavior == "accept and notify") + return UnhandledPromptBehavior::AcceptAndNotify; if (unhandledPromptBehavior == "ignore") return UnhandledPromptBehavior::Ignore; return std::nullopt; @@ -651,6 +655,12 @@ void WebDriverService::newSession(RefPtr&& parameters, FunctionsetString(ASCIILiteral("unhandledPromptBehavior"), "accept"); break; + case UnhandledPromptBehavior::DismissAndNotify: + capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "dismiss and notify"); + break; + case UnhandledPromptBehavior::AcceptAndNotify: + capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept and notify"); + break; case UnhandledPromptBehavior::Ignore: capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "ignore"); break;