Skip to content

Commit c8e2941

Browse files
committed
implementing pressKey, behat/mink to 1.8@dev
1 parent 8684ee4 commit c8e2941

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
"require": {
2323
"php": ">=5.3.1",
24-
"behat/mink": "~1.7@dev",
24+
"behat/mink": "~1.8@dev",
2525
"instaclick/php-webdriver": "~1.1"
2626
},
2727

src/Selenium2Driver.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,49 @@ public function keyUp($xpath, $char, $modifier = null)
881881
$this->trigger($xpath, 'keyup', $options);
882882
}
883883

884+
/**
885+
* {@inheritdoc}
886+
*/
887+
public function pressKey($xpath, $char, $modifier = null)
888+
{
889+
$keys = array();
890+
891+
$modifier = $this->keyModifier($modifier);
892+
if ($modifier) {
893+
$keys[] = $modifier;
894+
}
895+
896+
$keys[] = $char;
897+
898+
if ($modifier) {
899+
$keys[] = Key::NULL_KEY;
900+
}
901+
902+
$this->findElement($xpath)->postValue(array('value' => array_map('strval', $keys)));
903+
}
904+
905+
/**
906+
* Converts alt/ctrl/shift/meta to corresponded Key::* constant
907+
*
908+
* @param string $modifier
909+
*
910+
* @return string
911+
*/
912+
private function keyModifier($modifier)
913+
{
914+
if ($modifier === 'alt') {
915+
$modifier = Key::ALT;
916+
} else if ($modifier === 'ctrl') {
917+
$modifier = Key::CONTROL;
918+
} else if ($modifier === 'shift') {
919+
$modifier = Key::SHIFT;
920+
} else if ($modifier === 'meta') {
921+
$modifier = Key::META;
922+
}
923+
924+
return $modifier;
925+
}
926+
884927
/**
885928
* {@inheritdoc}
886929
*/

0 commit comments

Comments
 (0)