From 938d0763f6babf877be7ea79b3255abbfd49095d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 20 Nov 2020 08:52:58 +0800 Subject: [PATCH 1/2] MDL-70148 behat: Wait after opening the user menu The version of Boost used in Moodle 3.5 does not have any pendingJS checks and it is not possible to add them. We need to use the poor-person's alternative and fall back to a short wait to allow the menu to open before interacting with it. This may still allow for failures on extremely slow systems but the risk is extremely minimal. --- admin/tool/behat/tests/behat/keyboard.feature | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/admin/tool/behat/tests/behat/keyboard.feature b/admin/tool/behat/tests/behat/keyboard.feature index ca9a74f02f3..76fc62c5c79 100644 --- a/admin/tool/behat/tests/behat/keyboard.feature +++ b/admin/tool/behat/tests/behat/keyboard.feature @@ -35,6 +35,11 @@ Feature: Verify that keyboard steps work as expected | saffronr | saffron.rutledge@example.com | Saffron | Rutledge | And I log in as "saffronr" And I click on "Saffron Rutledge" "link" in the ".usermenu" "css_element" + # The version of Boost used in Moodle 3.5 does not have any pendingJS checks and it is not possible to add them. + # We need to use the poor-person's alternative and fall back to a short wait to allow the menu to open before + # interacting with it. + # This may still allow for failures on extremely slow systems but the risk is extremely minimal. + And I wait "1" seconds When I press the up key Then the focused element is "Log out" "link" From e32b77b7a39772b63a22dcbfca5d36c5029458c8 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 20 Nov 2020 09:03:09 +0800 Subject: [PATCH 2/2] MDL-70148 behat: Use key_press for autocomplete escape In Moodle 3.5 dialogues are focused too frequently and active focus is often wrong. This means that the dialogue has focus after selecting an element in a form autocomplete element. As a result, pressing the escape key causes the dialogue to be closed. The older `key_press` call is sufficient to close the autocomplete in the cases where this is needed, but will not cuase the dialogue to be closed. --- lib/behat/form_field/behat_form_autocomplete.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/behat/form_field/behat_form_autocomplete.php b/lib/behat/form_field/behat_form_autocomplete.php index 238bbeecc35..d6b29c20fac 100644 --- a/lib/behat/form_field/behat_form_autocomplete.php +++ b/lib/behat/form_field/behat_form_autocomplete.php @@ -82,8 +82,9 @@ class behat_form_autocomplete extends behat_form_text { } $this->wait_for_pending_js(); - // Press the escape to close the autocomplete suggestions list. - behat_base::type_keys($this->session, [behat_keys::ESCAPE]); + // Note: This does not make use of the `type_keys` API because it can cause some modals to close. + // This is not an issue in later versions of Moodle where the autocomplete handling has been updated. + $this->key_press(27); $this->wait_for_pending_js(); } }