From c8e29413911557d05574ed05cfdf25cdada4e6a2 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 15 Jan 2019 23:53:28 +0200 Subject: [PATCH] implementing pressKey, behat/mink to 1.8@dev --- composer.json | 2 +- src/Selenium2Driver.php | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bda59eae..f83c50c9 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php": ">=5.3.1", - "behat/mink": "~1.7@dev", + "behat/mink": "~1.8@dev", "instaclick/php-webdriver": "~1.1" }, diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 87d25065..458c88d2 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -881,6 +881,49 @@ public function keyUp($xpath, $char, $modifier = null) $this->trigger($xpath, 'keyup', $options); } + /** + * {@inheritdoc} + */ + public function pressKey($xpath, $char, $modifier = null) + { + $keys = array(); + + $modifier = $this->keyModifier($modifier); + if ($modifier) { + $keys[] = $modifier; + } + + $keys[] = $char; + + if ($modifier) { + $keys[] = Key::NULL_KEY; + } + + $this->findElement($xpath)->postValue(array('value' => array_map('strval', $keys))); + } + + /** + * Converts alt/ctrl/shift/meta to corresponded Key::* constant + * + * @param string $modifier + * + * @return string + */ + private function keyModifier($modifier) + { + if ($modifier === 'alt') { + $modifier = Key::ALT; + } else if ($modifier === 'ctrl') { + $modifier = Key::CONTROL; + } else if ($modifier === 'shift') { + $modifier = Key::SHIFT; + } else if ($modifier === 'meta') { + $modifier = Key::META; + } + + return $modifier; + } + /** * {@inheritdoc} */