From c1ee80fef54d7072db22ccefc980fa59f99b82ae Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 26 Jun 2014 09:59:49 +0800 Subject: [PATCH] MDL-46061 behat: Fixed blur event problem for atto_image atto_image look for blur event after changing width/height Added a new step to get focus off the element, so this can work. --- .../plugins/image/tests/behat/image.feature | 8 ++++---- lib/tests/behat/behat_general.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/editor/atto/plugins/image/tests/behat/image.feature b/lib/editor/atto/plugins/image/tests/behat/image.feature index 19bd61d0c48..b7bed96de35 100644 --- a/lib/editor/atto/plugins/image/tests/behat/image.feature +++ b/lib/editor/atto/plugins/image/tests/behat/image.feature @@ -18,23 +18,23 @@ Feature: Add images to Atto And I click on "Select this file" "button" And I set the field "Describe this image" to "It's the Moodle" # Wait for the page to "settle". - And I wait "2" seconds + And I wait until the page is ready And the field "Width" matches value "204" And the field "Height" matches value "61" And I set the field "Auto size" to "1" And I set the field "Width" to "2040" # Trigger blur on the width field. - And I set the field "Alignment" to "Bottom" + And I take focus off "Width" "field" And the field "Height" matches value "610" And I set the field "Height" to "61" # Trigger blur on the height field. - And I set the field "Alignment" to "Bottom" + And I take focus off "Height" "field" And the field "Width" matches value "204" And I set the field "Auto size" to "0" And I set the field "Width" to "123" And I set the field "Height" to "456" # Trigger blur on the height field. - And I set the field "Alignment" to "Bottom" + And I take focus off "Height" "field" And the field "Width" matches value "123" And the field "Height" matches value "456" And I click on "Save image" "button" diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 99ce17b3059..26561426741 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -282,6 +282,26 @@ class behat_general extends behat_base { $node->click(); } + /** + * Sets the focus and takes away the focus from an element, generating blur JS event. + * + * @When /^I take focus off "(?P(?:[^"]|\\")*)" "(?P[^"]*)"$/ + * @param string $element Element we look for + * @param string $selectortype The type of what we look for + */ + public function i_take_focus_off_field($element, $selectortype) { + if (!$this->running_javascript()) { + throw new ExpectationException('Can\'t take focus off from "' . $element . '" in non-js mode', $this->getSession()); + } + // Gets the node based on the requested selector type and locator. + $node = $this->get_selected_node($selectortype, $element); + $this->ensure_node_is_visible($node); + + // Ensure element is focused before taking it off. + $node->focus(); + $node->blur(); + } + /** * Clicks the specified element and confirms the expected dialogue. *