From 2116de5f80c033cc88a2c9e4e52321ccafa68ef1 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 10 Feb 2015 14:10:20 +0000 Subject: [PATCH] MDL-49154 behat: step to type with focus on a given element --- lib/tests/behat/behat_general.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d8d5264991a..e56b1c2153a 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -382,6 +382,23 @@ class behat_general extends behat_base { $node->click(); } + /** + * Simulate pressing a sequence of keys. + * @When /^I type "(?P(?:[^"]|\\")*)" into the "(?P(?:[^"]|\\")*)" "(?P[^"]*)"$/ + * @param string $keys the keys to press. + * @param string $element Element we look for + * @param string $selectortype The type of what we look for + */ + public function i_type_into_the($keys, $element, $selectortype) { + $node = $this->get_selected_node($selectortype, $element); + $this->ensure_node_is_visible($node); + foreach (str_split($keys) as $key) { + $node->keyDown($key); + $node->keyPress($key); + $node->keyUp($key); + } + } + /** * Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental. * -- 2.36.1