Skip to content

Commit

Permalink
MDL-72152 Behat: No way to test key shortcuts with letter keys
Browse files Browse the repository at this point in the history
Extends the existing step 'And I press the Shift Left key' so that
it supports letter/other keys: 'And I press the Ctrl C key'.
  • Loading branch information
sammarshallou authored and andrewnicols committed Aug 26, 2021
1 parent 2575add commit e563d32
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/tests/behat/behat_general.php
Expand Up @@ -1717,7 +1717,7 @@ public function i_type(string $keys): void {
}

/**
* Press a named key with an optional set of modifiers.
* Press a named or character key with an optional set of modifiers.
*
* Supported named keys are:
* - up
Expand All @@ -1735,6 +1735,8 @@ public function i_type(string $keys): void {
* - enter
* - tab
*
* You can also use a single character for the key name e.g. 'Ctrl C'.
*
* Supported moderators are:
* - shift
* - ctrl
Expand Down Expand Up @@ -1830,7 +1832,12 @@ public function i_press_named_key(string $modifiers, string $key): void {
$keys[] = behat_keys::SPACE;
break;
default:
throw new \coding_exception("Unknown key '$key'}");
// You can enter a single ASCII character (e.g. a letter) to directly type that key.
if (strlen($key) === 1) {
$keys[] = strtolower($key);
} else {
throw new \coding_exception("Unknown key '$key'}");
}
}

behat_base::type_keys($this->getSession(), $keys);
Expand Down

0 comments on commit e563d32

Please sign in to comment.