Skip to content

Commit

Permalink
implementing pressKey, behat/mink to 1.8@dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-andreyev committed Jan 15, 2019
1 parent 8684ee4 commit c8e2941
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

"require": {
"php": ">=5.3.1",
"behat/mink": "~1.7@dev",
"behat/mink": "~1.8@dev",
"instaclick/php-webdriver": "~1.1"
},

Expand Down
43 changes: 43 additions & 0 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down

0 comments on commit c8e2941

Please sign in to comment.