From 33eb0adf0cbb94907d93d80bb6d528523bd8eeb8 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Thu, 22 Oct 2015 16:27:48 +1300 Subject: [PATCH] Add ability to confirm/dismiss dialogs after clicking in elements --- README.md | 4 ++++ .../BehatExtension/Context/BasicContext.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 2d0b8aa..4af1773 100644 --- a/README.md +++ b/README.md @@ -591,6 +591,10 @@ It's based on the `vendor/bin/behat -di @cms` output. Given /^I (?:press|follow) the "([^"]*)" (?:button|link), confirming the dialog$/ Given /^I (?:press|follow) the "([^"]*)" (?:button|link), dismissing the dialog$/ + + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, confirming the dialog$/ + + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, dismissing the dialog$/ Given /^I confirm the dialog$/ diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index a6ee63b..f629258 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -394,6 +394,27 @@ JS; $element->click(); } + + /** + * Needs to be in single command to avoid "unexpected alert open" errors in Selenium. + * Example: I click "Delete" in the ".actions" element, confirming the dialog + * + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, confirming the dialog$/ + */ + public function iClickInTheElementConfirmingTheDialog($clickType, $text, $selector) { + $this->iClickInTheElement($clickType, $text, $selector); + $this->iConfirmTheDialog(); + } + /** + * Needs to be in single command to avoid "unexpected alert open" errors in Selenium. + * Example: I click "Delete" in the ".actions" element, dismissing the dialog + * + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, dismissing the dialog$/ + */ + public function iClickInTheElementDismissingTheDialog($clickType, $text, $selector) { + $this->iClickInTheElement($clickType, $text, $selector); + $this->iDismissTheDialog(); + } /** * @Given /^I type "([^"]*)" into the dialog$/