From c5d0f7605ae2c4f15c46333358af55164f1854b8 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 15 Jul 2021 09:42:34 +0100 Subject: [PATCH] MDL-72152 Behat: No way to test key shortcuts with letter keys 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'. --- lib/tests/behat/behat_general.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 40d03e4f4a5..237d653a8cf 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1717,7 +1717,7 @@ EOF; } /** - * 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 @@ -1735,6 +1735,8 @@ EOF; * - enter * - tab * + * You can also use a single character for the key name e.g. 'Ctrl C'. + * * Supported moderators are: * - shift * - ctrl @@ -1830,7 +1832,12 @@ EOF; $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);