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} */