MDL-48653 behat: Steps to click and dismiss a dialogue.
authorTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 18 Dec 2014 19:29:29 +0000 (19:29 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Thu, 18 Dec 2014 19:29:29 +0000 (19:29 +0000)
We already had the corresponding
    I click on "Home" "link" confirming the dialogue
but I needed the opposite
    I click on "Home" "link" dismissing the dialogue

lib/tests/behat/behat_general.php

index b0a02c5..778f0f9 100644 (file)
@@ -206,6 +206,14 @@ class behat_general extends behat_base {
         $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
     }
 
+    /**
+     * Dismisses the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental.
+     * @Given /^I dismiss the currently displayed dialog$/
+     */
+    public function dismiss_currently_displayed_alert_dialog() {
+        $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
+    }
+
     /**
      * Clicks link with specified id|title|alt|text.
      *
@@ -344,6 +352,18 @@ class behat_general extends behat_base {
         $this->accept_currently_displayed_alert_dialog();
     }
 
+    /**
+     * Clicks the specified element and dismissing the expected dialogue.
+     *
+     * @When /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" dismissing the dialogue$/
+     * @throws ElementNotFoundException Thrown by behat_base::find
+     * @param string $link
+     */
+    public function i_click_on_dismissing_the_dialogue($element, $selectortype) {
+        $this->i_click_on($element, $selectortype);
+        $this->dismiss_currently_displayed_alert_dialog();
+    }
+
     /**
      * Click on the element of the specified type which is located inside the second element.
      *