From 9c35ea1040d2940cca1e3af1ba8c1a0d2fcc85d2 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 17 Jun 2020 14:50:04 +0800 Subject: [PATCH 1/4] MDL-70148 behat: Add steps to send keys without an element --- admin/tool/behat/tests/behat/keyboard.feature | 52 ++++++ lib/behat/behat_base.php | 42 +++++ lib/tests/behat/behat_general.php | 149 +++++++++++++++++- 3 files changed, 237 insertions(+), 6 deletions(-) create mode 100644 admin/tool/behat/tests/behat/keyboard.feature diff --git a/admin/tool/behat/tests/behat/keyboard.feature b/admin/tool/behat/tests/behat/keyboard.feature new file mode 100644 index 00000000000..ca9a74f02f3 --- /dev/null +++ b/admin/tool/behat/tests/behat/keyboard.feature @@ -0,0 +1,52 @@ +@tool_behat +Feature: Verify that keyboard steps work as expected + In order to use behat step definitions + As a test writer + I need to verify that the keyboard steps work as expected + + @javascript + Scenario: Typing keys into a field causes them to be input + Given the following "users" exist: + | username | email | firstname | lastname | password | + | saffronr | saffron.rutledge@example.com | Saffron | Rutledge | flowerpower | + Given I click on "Log in" "link" + And I click on "Username" "field" + When I type "saffronr" + And I press the tab key + And I type "flowerpower" + And I press enter + Then I should see "You are logged in as Saffron Rutledge" + + @javascript + Scenario: Using tab changes focus to the next or previous field + Given I click on "Log in" "link" + And I click on "Username" "field" + And the focused element is "Username" "field" + When I press the tab key + Then the focused element is "Password" "field" + + And I press the shift tab key + And the focused element is "Username" "field" + + @javascript + Scenario: Using the arrow keys allows me to navigate through menus + Given the following "users" exist: + | username | email | firstname | lastname | + | 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" + When I press the up key + Then the focused element is "Log out" "link" + + @javascript + Scenario: The escape key can be used to close a dialogue + Given the following "course" exists: + | fullname | C1| + | shortname | C1 | + And I log in as "admin" + And I am on "C1" course homepage + And I navigate to course participants + And I press "Enrol users" + And "Enrol users" "dialogue" should be visible + When I press the escape key + Then "Enrol users" "dialogue" should not be visible diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index db165c7101c..57688c8d671 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -38,6 +38,10 @@ use Behat\Mink\Session; require_once(__DIR__ . '/classes/component_named_selector.php'); require_once(__DIR__ . '/classes/component_named_replacement.php'); +// Alias the WebDriver\Key class to behat_keys to make future transition to a different WebDriver implementation +// easier. +class_alias('WebDriver\\Key', 'behat_keys'); + /** * Steps definitions base class. * @@ -264,6 +268,44 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { ]; } + /** + * Send key presses straight to the currently active element. + * + * The `$keys` array contains a list of key values to send to the session as defined in the WebDriver and JsonWire + * specifications: + * - JsonWire: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidkeys + * - W3C WebDriver: https://www.w3.org/TR/webdriver/#keyboard-actions + * + * This may be a combination of typable characters, modifier keys, and other supported keypoints. + * + * The NULL_KEY should be used to release modifier keys. If the NULL_KEY is not used then modifier keys will remain + * in the pressed state. + * + * Example usage: + * + * behat_base::type_keys($this->getSession(), [behat_keys::SHIFT, behat_keys::TAB, behat_keys::NULL_KEY]); + * behat_base::type_keys($this->getSession(), [behat_keys::ENTER, behat_keys::NULL_KEY]); + * behat_base::type_keys($this->getSession(), [behat_keys::ESCAPE, behat_keys::NULL_KEY]); + * + * It can also be used to send text input, for example: + * + * behat_base::type_keys( + * $this->getSession(), + * ['D', 'o', ' ', 'y', 'o', 'u', ' ', 'p', 'l', 'a' 'y', ' ', 'G', 'o', '?', behat_base::NULL_KEY] + * ); + * + * + * Please note: This function does not use the element/sendKeys variants but sends keys straight to the browser. + * + * @param Session $session + * @param string[] $keys + */ + public static function type_keys(Session $session, array $keys): void { + $session->getDriver()->getWebDriverSession()->keys([ + 'value' => $keys, + ]); + } + /** * Finds DOM nodes in the page using named selectors. * diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 49b2fdd63c0..469fe0d715f 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -27,12 +27,12 @@ require_once(__DIR__ . '/../../behat/behat_base.php'); -use Behat\Mink\Exception\ExpectationException as ExpectationException, - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, - Behat\Mink\Exception\DriverException as DriverException, - WebDriver\Exception\NoSuchElement as NoSuchElement, - WebDriver\Exception\StaleElementReference as StaleElementReference, - Behat\Gherkin\Node\TableNode as TableNode; +use Behat\Gherkin\Node\TableNode as TableNode; +use Behat\Mink\Exception\DriverException as DriverException; +use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; +use Behat\Mink\Exception\ExpectationException as ExpectationException; +use WebDriver\Exception\NoSuchElement as NoSuchElement; +use WebDriver\Exception\StaleElementReference as StaleElementReference; /** * Cross component steps definitions. @@ -1710,6 +1710,143 @@ EOF; } } + /** + * Send key presses to the browser without first changing focusing, or applying the key presses to a specific + * element. + * + * Example usage of this step: + * When I type "Penguin" + * + * @When I type :keys + * @param string $keys The key, or list of keys, to type + */ + public function i_type(string $keys): void { + behat_base::type_keys($this->getSession(), str_split($keys)); + } + + /** + * Press a named key with an optional set of modifiers. + * + * Supported named keys are: + * - up + * - down + * - left + * - right + * - pageup|page_up + * - pagedown|page_down + * - home + * - end + * - insert + * - delete + * - backspace + * - escape + * - enter + * - tab + * + * Supported moderators are: + * - shift + * - ctrl + * - alt + * - meta + * + * Example usage of this new step: + * When I press the up key + * When I press the space key + * When I press the shift tab key + * + * Multiple moderator keys can be combined using the '+' operator, for example: + * When I press the ctrl+shift enter key + * When I press the ctrl + shift enter key + * + * @When /^I press the (?P.* )?(?P.*) key$/ + * @param string $modifiers A list of keyboard modifiers, separated by the `+` character + * @param string $key The name of the key to press + */ + public function i_press_named_key(string $modifiers, string $key): void { + behat_base::require_javascript_in_session($this->getSession()); + + $keys = []; + + foreach (explode('+', $modifiers) as $modifier) { + switch (strtoupper(trim($modifier))) { + case '': + break; + case 'SHIFT': + $keys[] = behat_keys::SHIFT; + break; + case 'CTRL': + $keys[] = behat_keys::CONTROL; + break; + case 'ALT': + $keys[] = behat_keys::ALT; + break; + case 'META': + $keys[] = behat_keys::META; + break; + default: + throw new \coding_exception("Unknown modifier key '$modifier'}"); + } + } + + $modifier = trim($key); + switch (strtoupper($key)) { + case 'UP': + $keys[] = behat_keys::UP_ARROW; + break; + case 'DOWN': + $keys[] = behat_keys::DOWN_ARROW; + break; + case 'LEFT': + $keys[] = behat_keys::LEFT_ARROW; + break; + case 'RIGHT': + $keys[] = behat_keys::RIGHT_ARROW; + break; + case 'HOME': + $keys[] = behat_keys::HOME; + break; + case 'END': + $keys[] = behat_keys::END; + break; + case 'INSERT': + $keys[] = behat_keys::INSERT; + break; + case 'BACKSPACE': + $keys[] = behat_keys::BACKSPACE; + break; + case 'DELETE': + $keys[] = behat_keys::DELETE; + break; + case 'PAGEUP': + case 'PAGE_UP': + $keys[] = behat_keys::PAGE_UP; + break; + case 'PAGEDOWN': + case 'PAGE_DOWN': + $keys[] = behat_keys::PAGE_DOWN; + break; + case 'ESCAPE': + $keys[] = behat_keys::ESCAPE; + break; + case 'ENTER': + $keys[] = behat_keys::ENTER; + break; + case 'TAB': + $keys[] = behat_keys::TAB; + break; + case 'SPACE': + $keys[] = behat_keys::SPACE; + break; + default: + throw new \coding_exception("Unknown key '$key'}"); + } + + // Always send the NULL key as the last key. + $keys[] = behat_keys::NULL_KEY; + + behat_base::type_keys($this->getSession(), $keys); + } + /** * Trigger a keydown event for a key on a specific element. * From ba34d6e225dd30408ba9dd073abe6e7938aa7243 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 22 Jun 2020 10:39:57 +0800 Subject: [PATCH 2/4] MDL-70148 behat: Update steps for keyboard --- .../tests/behat/manage_data_requests.feature | 2 +- .../tests/behat/manage_purposes.feature | 6 ++-- .../tests/behat/course_competencies.feature | 4 +-- admin/tool/lp/tests/behat/plan_crud.feature | 4 +-- .../tests/behat/edit_activities.feature | 2 +- .../tests/behat/edit_activities.feature | 2 +- cohort/tests/behat/add_cohort.feature | 2 +- .../tests/behat/edit_delete_sections.feature | 2 +- .../tests/behat/edit_delete_sections.feature | 2 +- .../tests/behat/activities_edit_name.feature | 5 ++- .../tests/behat/edit_categories.feature | 2 +- enrol/tests/behat/add_to_group.feature | 2 +- .../grader/tests/behat/ajax_grader.feature | 18 +++++----- .../form_field/behat_form_autocomplete.php | 10 +++--- lib/tests/behat/action_menu.feature | 2 +- lib/tests/behat/behat_general.php | 24 ++++--------- .../behat/message_manage_preferences.feature | 4 +-- mod/forum/tests/behat/advanced_search.feature | 2 +- mod/lti/tests/behat/renametool.feature | 2 +- .../editing_add_from_question_bank.feature | 2 +- .../editing_set_marks_no_attempts.feature | 3 +- .../editing_set_marks_with_attempts.feature | 3 +- .../behat/filter_questions_by_tag.feature | 2 +- .../tests/behat/breakdown_by_activity.feature | 4 +-- tag/tests/behat/collections.feature | 2 +- tag/tests/behat/edit_tag.feature | 17 +++------ user/tests/behat/edit_user_roles.feature | 4 +-- user/tests/behat/filter_participants.feature | 36 +++++++++---------- 28 files changed, 73 insertions(+), 97 deletions(-) diff --git a/admin/tool/dataprivacy/tests/behat/manage_data_requests.feature b/admin/tool/dataprivacy/tests/behat/manage_data_requests.feature index bf839ed6542..0c0d943265b 100644 --- a/admin/tool/dataprivacy/tests/behat/manage_data_requests.feature +++ b/admin/tool/dataprivacy/tests/behat/manage_data_requests.feature @@ -46,7 +46,7 @@ Feature: Manage data requests And I open the action menu in "John Doe" "table_row" And I should see "View the request" But I should not see "Mark as complete" - And I press key "27" in ".moodle-actionmenu" "css_element" + And I press the escape key And I open the action menu in "Jane Doe" "table_row" And I choose "Mark as complete" in the open action menu And I should see "Do you really want to mark this user enquiry as complete?" diff --git a/admin/tool/dataprivacy/tests/behat/manage_purposes.feature b/admin/tool/dataprivacy/tests/behat/manage_purposes.feature index dcd0c2a7ae3..6619bdac58b 100644 --- a/admin/tool/dataprivacy/tests/behat/manage_purposes.feature +++ b/admin/tool/dataprivacy/tests/behat/manage_purposes.feature @@ -15,10 +15,10 @@ Feature: Manage data storage purposes And I click on ".form-autocomplete-downarrow" "css_element" in the "Lawful bases" "form_row" And I click on "Contract (GDPR Art. 6.1(b))" "list_item" And I click on "Legal obligation (GDPR Art 6.1(c))" "list_item" - And I press key "27" in the field "Lawful bases" + And I press the escape key And I click on ".form-autocomplete-downarrow" "css_element" in the "Sensitive personal data processing reasons" "form_row" And I click on "Explicit consent (GDPR Art. 9.2(a))" "list_item" - And I press key "27" in the field "Sensitive personal data processing reasons" + And I press the escape key And I set the field "retentionperiodnumber" to "2" When I press "Save" Then I should see "Purpose 1" in the "List of data purposes" "table" @@ -36,7 +36,7 @@ Feature: Manage data storage purposes And I click on "Legal obligation (GDPR Art 6.1(c))" "text" in the ".form-autocomplete-selection" "css_element" And I click on ".form-autocomplete-downarrow" "css_element" in the "Lawful bases" "form_row" And I click on "Vital interests (GDPR Art. 6.1(d))" "list_item" - And I press key "27" in the field "Lawful bases" + And I press the escape key And I set the field "retentionperiodnumber" to "3" And I click on "protected" "checkbox" When I press "Save changes" diff --git a/admin/tool/lp/tests/behat/course_competencies.feature b/admin/tool/lp/tests/behat/course_competencies.feature index bb57d2277cf..b3caddc7aae 100644 --- a/admin/tool/lp/tests/behat/course_competencies.feature +++ b/admin/tool/lp/tests/behat/course_competencies.feature @@ -53,11 +53,11 @@ Feature: See the competencies for an activity on the course competencies page. Then I should see "Test-Comp1" And I should see "Test-Comp2" And I set the field "Filter competencies by resource or activity" to "PageName1" - And I press key "13" in the field "Filter competencies by resource or activity" + And I press the enter key And I should see "Test-Comp1" And I should not see "Test-Comp2" And I set the field "Filter competencies by resource or activity" to "PageName2" - And I press key "13" in the field "Filter competencies by resource or activity" + And I press the enter key And I should not see "Test-Comp1" And I should not see "Test-Comp2" And I should see "No competencies have been linked to this activity or resource." diff --git a/admin/tool/lp/tests/behat/plan_crud.feature b/admin/tool/lp/tests/behat/plan_crud.feature index 0fbbfd183a0..55c085a70c1 100644 --- a/admin/tool/lp/tests/behat/plan_crud.feature +++ b/admin/tool/lp/tests/behat/plan_crud.feature @@ -30,7 +30,7 @@ Feature: Manage plearning plan And I click on ".template-userplans" "css_element" in the "Science template" "table_row" And I open the autocomplete suggestions list And I click on "Admin User" item in the autocomplete list - And I press key "27" in the field "Select users to create learning plans for" + And I press the escape key When I click on "Create learning plans" "button" Then I should see "A learning plan was created" And I should see "Admin User" in the "Science template" "table_row" @@ -55,7 +55,7 @@ Feature: Manage plearning plan And I click on ".template-cohorts" "css_element" in the "Science template cohort" "table_row" And I click on ".form-autocomplete-downarrow" "css_element" And I click on "cohort plan" item in the autocomplete list - And I press key "27" in the field "Select cohorts to sync" + And I press the escape key When I click on "Add cohorts" "button" Then I should see "2 learning plans were created." And I follow "Learning plan templates" diff --git a/blocks/site_main_menu/tests/behat/edit_activities.feature b/blocks/site_main_menu/tests/behat/edit_activities.feature index 3b5d632dfed..0f6d8c28e37 100644 --- a/blocks/site_main_menu/tests/behat/edit_activities.feature +++ b/blocks/site_main_menu/tests/behat/edit_activities.feature @@ -14,7 +14,7 @@ Feature: Edit activities in main menu block | Forum name | My forum name | And I click on "Edit title" "link" in the "My forum name" activity in site main menu block And I set the field "New name for activity My forum name" to "New forum name" - And I press key "13" in the field "New name for activity My forum name" + And I press the enter key Then I should not see "My forum name" And I should see "New forum name" And I follow "New forum name" diff --git a/blocks/social_activities/tests/behat/edit_activities.feature b/blocks/social_activities/tests/behat/edit_activities.feature index 2cf87a5089e..984b73173a3 100644 --- a/blocks/social_activities/tests/behat/edit_activities.feature +++ b/blocks/social_activities/tests/behat/edit_activities.feature @@ -27,7 +27,7 @@ Feature: Edit activities in social activities block And I press "Save and return to course" And I click on "Edit title" "link" in the "My forum name" activity in social activities block And I set the field "New name for activity My forum name" to "New forum name" - And I press key "13" in the field "New name for activity My forum name" + And I press the enter key Then I should not see "My forum name" in the "Social activities" "block" And I should see "New forum name" And I follow "New forum name" diff --git a/cohort/tests/behat/add_cohort.feature b/cohort/tests/behat/add_cohort.feature index b93d41fb983..9bc546951fa 100644 --- a/cohort/tests/behat/add_cohort.feature +++ b/cohort/tests/behat/add_cohort.feature @@ -64,7 +64,7 @@ Feature: Add cohorts of users When I follow "Cohorts" And I click on "Edit cohort name" "link" in the "Test cohort name" "table_row" And I set the field "New name for cohort Test cohort name" to "Students cohort" - And I press key "13" in the field "New name for cohort Test cohort name" + And I press the enter key Then I should not see "Test cohort name" And I should see "Students cohort" And I follow "Cohorts" diff --git a/course/format/topics/tests/behat/edit_delete_sections.feature b/course/format/topics/tests/behat/edit_delete_sections.feature index e55b58deff9..a1e205b3c19 100644 --- a/course/format/topics/tests/behat/edit_delete_sections.feature +++ b/course/format/topics/tests/behat/edit_delete_sections.feature @@ -55,7 +55,7 @@ Feature: Sections can be edited and deleted in topics format Scenario: Inline edit section name in topics format When I click on "Edit topic name" "link" in the "li#section-1" "css_element" And I set the field "New name for topic Topic 1" to "Midterm evaluation" - And I press key "13" in the field "New name for topic Topic 1" + And I press the enter key Then I should not see "Topic 1" in the "region-main" "region" And "New name for topic" "field" should not exist And I should see "Midterm evaluation" in the "li#section-1" "css_element" diff --git a/course/format/weeks/tests/behat/edit_delete_sections.feature b/course/format/weeks/tests/behat/edit_delete_sections.feature index a51a803a322..5d8ff891130 100644 --- a/course/format/weeks/tests/behat/edit_delete_sections.feature +++ b/course/format/weeks/tests/behat/edit_delete_sections.feature @@ -56,7 +56,7 @@ Feature: Sections can be edited and deleted in weeks format Scenario: Inline edit section name in weeks format When I click on "Edit week name" "link" in the "li#section-1" "css_element" And I set the field "New name for week 1 May - 7 May" to "Midterm evaluation" - And I press key "13" in the field "New name for week 1 May - 7 May" + And I press the enter key Then I should not see "1 May - 7 May" in the "region-main" "region" And "New name for week" "field" should not exist And I should see "Midterm evaluation" in the "li#section-1" "css_element" diff --git a/course/tests/behat/activities_edit_name.feature b/course/tests/behat/activities_edit_name.feature index 29e8911821c..7372c1741a1 100644 --- a/course/tests/behat/activities_edit_name.feature +++ b/course/tests/behat/activities_edit_name.feature @@ -23,7 +23,7 @@ Feature: Edit activity name in-place # Rename activity And I click on "Edit title" "link" in the "//div[contains(@class,'activityinstance') and contains(.,'Test forum name')]" "xpath_element" And I set the field "New name for activity Test forum name" to "Good news" - And I press key "13" in the field "New name for activity Test forum name" + And I press the enter key Then I should not see "Test forum name" in the ".course-content" "css_element" And "New name for activity Test forum name" "field" should not exist And I should see "Good news" @@ -33,11 +33,10 @@ Feature: Edit activity name in-place # Cancel renaming And I click on "Edit title" "link" in the "//div[contains(@class,'activityinstance') and contains(.,'Good news')]" "xpath_element" And I set the field "New name for activity Good news" to "Terrible news" - And I press key "27" in the field "New name for activity Good news" + And I press the escape key And "New name for activity Good news" "field" should not exist And I should see "Good news" And I should not see "Terrible news" And I am on "Course 1" course homepage And I should see "Good news" And I should not see "Terrible news" - And I log out diff --git a/customfield/tests/behat/edit_categories.feature b/customfield/tests/behat/edit_categories.feature index 5fb4802a866..2b88046c088 100644 --- a/customfield/tests/behat/edit_categories.feature +++ b/customfield/tests/behat/edit_categories.feature @@ -22,7 +22,7 @@ Feature: Managers can manage categories for course custom fields And I navigate to "Courses > Course custom fields" in site administration And I click on "Edit category name" "link" in the "//div[contains(@class,'categoryinstance') and contains(.,'Category for test')]" "xpath_element" And I set the field "New value for Category for test" to "Good fields" - And I press key "13" in the field "New value for Category for test" + And I press the enter key Then I should not see "Category for test" in the "#customfield_catlist" "css_element" And "New value for Category for test" "field" should not exist And I should see "Good fields" in the "#customfield_catlist" "css_element" diff --git a/enrol/tests/behat/add_to_group.feature b/enrol/tests/behat/add_to_group.feature index 0a7aab9e5a7..e44f9c2610d 100644 --- a/enrol/tests/behat/add_to_group.feature +++ b/enrol/tests/behat/add_to_group.feature @@ -32,6 +32,6 @@ Feature: Users can be added to multiple groups at once And I click on "Group 1" item in the autocomplete list And I click on ".form-autocomplete-downarrow" "css_element" in the "student1" "table_row" And I click on "Group 2" item in the autocomplete list - And I press key "27" in the field "Edit groups for \"Student 1\"" + And I press the escape key And I click on "Save changes" "link" in the "student1" "table_row" Then I should see "Group 1, Group 2" diff --git a/grade/report/grader/tests/behat/ajax_grader.feature b/grade/report/grader/tests/behat/ajax_grader.feature index 358f9a5e276..072c5f04cf1 100644 --- a/grade/report/grader/tests/behat/ajax_grader.feature +++ b/grade/report/grader/tests/behat/ajax_grader.feature @@ -59,18 +59,18 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe Then I should see a grade field for "Student 2" and grade item "Item VU" And I should not see a feedback field for "Student 2" and grade item "Item VU" And I set the field "ajaxgrade" to "33" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And I should not see a grade field for "Student 2" and grade item "Item VU" And I should not see a feedback field for "Student 2" and grade item "Item VU" And I click on student "Student 3" for grade item "Item VU" And I set the field "ajaxgrade" to "50" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And I click on student "Student 3" for grade item "Item 1" And I set the field "ajaxgrade" to "80" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And I click on student "Student 3" for grade item "Item SU" And I set the field "ajaxgrade" to "Very good" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And the following should exist in the "user-grades" table: | -1- | -6- | -7- | -13- | -16- | | Student 2 | - | 33.00 | - | 33.00 | @@ -88,7 +88,7 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe And I should see a grade field for "Student 1" and grade item "Course total" And I should not see a feedback field for "Student 1" and grade item "Course total" And I set the field "ajaxgrade" to "90" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And the following should exist in the "user-grades" table: | -1- | -16- | | Student 1 | 90.00 | @@ -112,7 +112,7 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe And I should see a feedback field for "Student 2" and grade item "Item VU" And I set the field "ajaxgrade" to "33" And I set the field "ajaxfeedback" to "Student 2 VU feedback" - And I press key "13" in the field "ajaxfeedback" + And I press the enter key And I click on student "Student 3" for grade item "Item VL" And I should not see a grade field for "Student 3" and grade item "Item VL" And I should not see a feedback field for "Student 3" and grade item "Item VL" @@ -120,11 +120,11 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe And I should not see a grade field for "Student 3" and grade item "Item TU" And I should see a feedback field for "Student 3" and grade item "Item TU" And I set the field "ajaxfeedback" to "Student 3 TU feedback" - And I press key "13" in the field "ajaxfeedback" + And I press the enter key And I click on student "Student 2" for grade item "Item SU" And I set the field "ajaxgrade" to "Very good" And I set the field "ajaxfeedback" to "Student 2 SU feedback" - And I press key "13" in the field "ajaxfeedback" + And I press the enter key # Reload grader report: And I navigate to "View > User report" in the course gradebook And I navigate to "View > Grader report" in the course gradebook @@ -148,7 +148,7 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe Then I should see a grade field for "Student 2" and grade item "Item VU" And I should see a feedback field for "Student 2" and grade item "Item VU" And I set the field "ajaxgrade" to "33" - And I press key "13" in the field "ajaxgrade" + And I press the enter key And I click on student "Student 2" for grade item "Course total" And I should not see a grade field for "Student 3" and grade item "Course total" And I should not see a feedback field for "Student 3" and grade item "Course total" diff --git a/lib/behat/form_field/behat_form_autocomplete.php b/lib/behat/form_field/behat_form_autocomplete.php index 8b1d39080a0..238bbeecc35 100644 --- a/lib/behat/form_field/behat_form_autocomplete.php +++ b/lib/behat/form_field/behat_form_autocomplete.php @@ -78,14 +78,12 @@ class behat_form_autocomplete extends behat_form_text { $suggestion->click(); } else { // Press the return key to create a new tag. - // Note: We cannot use $this->key_press() because the keyPress action, in combination with the keyDown - // submits the form. - $this->field->keyDown(13); - $this->field->keyUp(13); + behat_base::type_keys($this->session, [behat_keys::ENTER]); } - $this->wait_for_pending_js(); - $this->key_press(27); + + // Press the escape to close the autocomplete suggestions list. + behat_base::type_keys($this->session, [behat_keys::ESCAPE]); $this->wait_for_pending_js(); } } diff --git a/lib/tests/behat/action_menu.feature b/lib/tests/behat/action_menu.feature index 994604161d8..06458e27032 100644 --- a/lib/tests/behat/action_menu.feature +++ b/lib/tests/behat/action_menu.feature @@ -12,7 +12,7 @@ Feature: Navigate action menu # The menu should now be visible. Then ".usermenu [role='menu']" "css_element" should be visible # Press down arrow. - And I press key "40" in "#actionmenuaction-1" "css_element" + And I press the down key # The menu should still be visible. And ".usermenu [role='menu']" "css_element" should be visible diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 469fe0d715f..dacbabc21c7 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1898,12 +1898,8 @@ EOF; } // Gets the node based on the requested selector type and locator. $node = $this->get_selected_node($selectortype, $element); - $driver = $this->getSession()->getDriver(); - if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { - $driver->post_key("\xEE\x80\x84", $node->getXpath()); - } else { - $driver->keyDown($node->getXpath(), "\t"); - } + $this->execute('behat_general::i_click_on', [$node, 'NodeElement']); + $this->execute('behat_general::i_press_named_key', ['', 'tab']); } /** @@ -2000,12 +1996,11 @@ EOF; * @throws DriverException */ public function i_manually_press_tab($shift = '') { - if (!$this->running_javascript()) { - throw new DriverException($shift . ' Tab press step is not available with Javascript disabled'); + if (empty($shift)) { + $this->execute('behat_general::i_press_named_key', ['', 'tab']); + } else { + $this->execute('behat_general::i_press_named_key', ['shift', 'tab']); } - - $value = ($shift == ' shift') ? [\WebDriver\Key::SHIFT . \WebDriver\Key::TAB] : [\WebDriver\Key::TAB]; - $this->getSession()->getDriver()->getWebDriverSession()->activeElement()->postValue(['value' => $value]); } /** @@ -2067,12 +2062,7 @@ EOF; * @throws DriverException */ public function i_manually_press_enter() { - if (!$this->running_javascript()) { - throw new DriverException('Enter press step is not available with Javascript disabled'); - } - - $value = [\WebDriver\Key::ENTER]; - $this->getSession()->getDriver()->getWebDriverSession()->activeElement()->postValue(['value' => $value]); + $this->execute('behat_general::i_press_named_key', ['', 'enter']); } /** diff --git a/message/tests/behat/message_manage_preferences.feature b/message/tests/behat/message_manage_preferences.feature index 65c013e92bb..42e6634d99a 100644 --- a/message/tests/behat/message_manage_preferences.feature +++ b/message/tests/behat/message_manage_preferences.feature @@ -102,7 +102,7 @@ Feature: Manage preferences And I open messaging And I select "Student 2" user in messaging And I set the field with xpath "//textarea[@data-region='send-message-txt']" to "Hi!" - And I press key "13" in "//textarea[@data-region='send-message-txt']" "xpath_element" + And I press the enter key Then I should see "Hi!" in the "//*[@data-region='message-drawer']//div[@data-region='content-message-container']" "xpath_element" Scenario: Sending a message after 'Use enter to send' is disabled @@ -113,7 +113,7 @@ Feature: Manage preferences And I go back in "view-settings" message drawer Then I select "Student 2" user in messaging And I set the field with xpath "//textarea[@data-region='send-message-txt']" to "Hi!" - And I press key "13" in "//textarea[@data-region='send-message-txt']" "xpath_element" + And I press the enter key And I should not see "Hi!" in the "//*[@data-region='message-drawer']//div[@data-region='content-message-container']" "xpath_element" And I press "Send message" And I should see "Hi!" in the "//*[@data-region='message-drawer']//div[@data-region='content-message-container']" "xpath_element" diff --git a/mod/forum/tests/behat/advanced_search.feature b/mod/forum/tests/behat/advanced_search.feature index 3fe90acaa23..90dd16298c8 100644 --- a/mod/forum/tests/behat/advanced_search.feature +++ b/mod/forum/tests/behat/advanced_search.feature @@ -131,7 +131,7 @@ Feature: The forum search allows users to perform advanced searches for forum po And I should see "Advanced search" And I set the field "Is tagged with" to "SearchedTag" And I click on "[data-value='SearchedTag']" "css_element" - And I press key "27" in the field "Is tagged with" + And I press the escape key When I press "Search forums" Then I should see "My subject" And I should not see "Your subjective" diff --git a/mod/lti/tests/behat/renametool.feature b/mod/lti/tests/behat/renametool.feature index 25eefbf7719..30eed0702d0 100644 --- a/mod/lti/tests/behat/renametool.feature +++ b/mod/lti/tests/behat/renametool.feature @@ -23,7 +23,7 @@ Feature: Rename external tools via inline editing | Activity name | Test tool activity 1 | And I click on "Edit title" "link" in the "li#section-1" "css_element" And I set the field "New name for activity Test tool activity 1" to "Test tool activity renamed" - And I press key "13" in the field "New name for activity Test tool activity 1" + And I press the enter key And I navigate to "Setup > Gradebook setup" in the course gradebook Then I should not see "Test tool activity 1" And I should see "Test tool activity renamed" diff --git a/mod/quiz/tests/behat/editing_add_from_question_bank.feature b/mod/quiz/tests/behat/editing_add_from_question_bank.feature index 3ff5acd4f33..94b56cf13e8 100644 --- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature +++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature @@ -44,7 +44,7 @@ Feature: Adding questions to a quiz from the question bank And I should see "bar" in the "question 02 name" "table_row" And I should see "qidnum" in the "question 02 name" "table_row" And I set the field "Filter by tags..." to "foo" - And I press key "13" in the field "Filter by tags..." + And I press the enter key And I should see "question 01 name" in the "categoryquestions" "table" And I should not see "question 02 name" in the "categoryquestions" "table" diff --git a/mod/quiz/tests/behat/editing_set_marks_no_attempts.feature b/mod/quiz/tests/behat/editing_set_marks_no_attempts.feature index 7b4184dcfbb..b4bee513a0b 100644 --- a/mod/quiz/tests/behat/editing_set_marks_no_attempts.feature +++ b/mod/quiz/tests/behat/editing_set_marks_no_attempts.feature @@ -36,8 +36,7 @@ Feature: Edit quiz marks with no attempts And I should see "Total of marks: 10.00" When I follow "Edit maximum mark" - And I wait until "li input[name=maxmark]" "css_element" exists - And I take focus off "li input[name=maxmark]" "css_element" + And I press the escape key Then I should see "7.00" And I should see "3.00" And I should see "Total of marks: 10.00" diff --git a/mod/quiz/tests/behat/editing_set_marks_with_attempts.feature b/mod/quiz/tests/behat/editing_set_marks_with_attempts.feature index a23acfbc58e..36c2edd02e9 100644 --- a/mod/quiz/tests/behat/editing_set_marks_with_attempts.feature +++ b/mod/quiz/tests/behat/editing_set_marks_with_attempts.feature @@ -46,8 +46,7 @@ Feature: Edit quiz marks with attempts And I should see "Total of marks: 10.00" When I follow "Edit maximum mark" - And I wait until "li input[name=maxmark]" "css_element" exists - And I take focus off "li input[name=maxmark]" "css_element" + And I press the escape key Then I should see "7.00" And I should see "3.00" And I should see "Total of marks: 10.00" diff --git a/question/tests/behat/filter_questions_by_tag.feature b/question/tests/behat/filter_questions_by_tag.feature index acbefe69762..ce9df72c5fe 100644 --- a/question/tests/behat/filter_questions_by_tag.feature +++ b/question/tests/behat/filter_questions_by_tag.feature @@ -36,6 +36,6 @@ Feature: The questions in the question bank can be filtered by tags @javascript Scenario: The questions can be filtered by tag When I set the field "Filter by tags..." to "foo" - And I press key "13" in the field "Filter by tags..." + And I press the enter key Then I should see "question 1 name" in the "categoryquestions" "table" And I should not see "question 2 name" in the "categoryquestions" "table" diff --git a/report/competency/tests/behat/breakdown_by_activity.feature b/report/competency/tests/behat/breakdown_by_activity.feature index dfa0876a6b9..62368c906d8 100644 --- a/report/competency/tests/behat/breakdown_by_activity.feature +++ b/report/competency/tests/behat/breakdown_by_activity.feature @@ -47,7 +47,7 @@ Feature: See the competencies for an activity Scenario: Go to the competency breakdown report When I navigate to "Reports > Competency breakdown" in current page administration And I set the field "Filter competencies by resource or activity" to "PageName1" - And I press key "13" in the field "Filter competencies by resource or activity" + And I press the enter key Then I should see "Test-Comp1" And I should not see "Test-Comp2" And I click on "Not rated" "link" @@ -56,6 +56,6 @@ Feature: See the competencies for an activity And I click on "Rate" "button" in the ".competency-grader" "css_element" And I click on "Close" "button" And I set the field "Filter competencies by resource or activity" to "No filters applied" - And I press key "13" in the field "Filter competencies by resource or activity" + And I press the enter key And I should see "Test-Comp1" And I should see "Test-Comp2" diff --git a/tag/tests/behat/collections.feature b/tag/tests/behat/collections.feature index eaad7277ae8..6cdb568b7c4 100644 --- a/tag/tests/behat/collections.feature +++ b/tag/tests/behat/collections.feature @@ -33,7 +33,7 @@ Feature: Managers can create and manage tag collections Scenario: Editing tag collections When I click on "Edit tag collection name" "link" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element" And I set the field "New name for tag collection Hobbies" to "Newname" - And I press key "13" in the field "New name for tag collection Hobbies" + And I press the enter key Then I should not see "Hobbies" And I should see "Newname" And I log out diff --git a/tag/tests/behat/edit_tag.feature b/tag/tests/behat/edit_tag.feature index 555facdb15e..4682edb587b 100644 --- a/tag/tests/behat/edit_tag.feature +++ b/tag/tests/behat/edit_tag.feature @@ -52,7 +52,6 @@ Feature: Users can edit tags to add description or rename And I should see "Dog" in the ".tag_list" "css_element" And I should see "Turtle" in the ".tag_list" "css_element" And I should see "Fish" in the ".tag_list" "css_element" - And I log out @javascript Scenario: Manager can change tag description, related tags and rename the tag from tag view page @@ -87,7 +86,6 @@ Feature: Users can edit tags to add description or rename And I should see "Turtle" in the ".tag_list" "css_element" And I should see "Fish" in the ".tag_list" "css_element" And I should not see "Dog" - And I log out Scenario: Renaming the tag from tag view page When I log in as "manager1" @@ -112,7 +110,6 @@ Feature: Users can edit tags to add description or rename | Tag name | KITTEN | And I press "Update" And "KITTEN" "text" should exist in the ".breadcrumb" "css_element" - And I log out @javascript Scenario: Manager can change tag description and rename the tag from tag manage page @@ -133,7 +130,6 @@ Feature: Users can edit tags to add description or rename And I should see "Dog" in the ".tag_list" "css_element" And I should see "Turtle" in the ".tag_list" "css_element" And I should see "Fish" in the ".tag_list" "css_element" - And I log out Scenario: Renaming the tag in edit tag form from tag manage page When I log in as "manager1" @@ -155,7 +151,6 @@ Feature: Users can edit tags to add description or rename And "Default collection" "text" should exist in the ".breadcrumb" "css_element" And I should see "KITTEN" And I should not see "Kitten" - And I log out @javascript Scenario: Renaming the tag using quick edit field on tag manage page @@ -165,7 +160,7 @@ Feature: Users can edit tags to add description or rename # Renaming tag to a valid name And I click on "Edit tag name" "link" in the "Cat" "table_row" And I set the field "New name for tag Cat" to "Kitten" - And I press key "13" in the field "New name for tag Cat" + And I press the enter key Then I should not see "Cat" And "New name for tag" "field" should not exist And I wait until "Kitten" "link" exists @@ -175,7 +170,7 @@ Feature: Users can edit tags to add description or rename # Renaming tag to an invalid name And I click on "Edit tag name" "link" in the "Turtle" "table_row" And I set the field "New name for tag Turtle" to "DOG" - And I press key "13" in the field "New name for tag Turtle" + And I press the enter key And I should see "The tag name is already in use. Do you want to combine these tags?" And I click on "Cancel" "button" in the "Confirm" "dialogue" And "New name for tag" "field" should not exist @@ -189,14 +184,13 @@ Feature: Users can edit tags to add description or rename # Cancel tag renaming And I click on "Edit tag name" "link" in the "Dog" "table_row" And I set the field "New name for tag Dog" to "Penguin" - And I press key "27" in the field "New name for tag Dog" + And I press the escape key And "New name for tag" "field" should not exist And I should see "Turtle" And I should not see "Penguin" And I follow "Default collection" And I should see "Turtle" And I should not see "Penguin" - And I log out @javascript Scenario: Combining tags when renaming @@ -205,13 +199,12 @@ Feature: Users can edit tags to add description or rename And I follow "Default collection" And I click on "Edit tag name" "link" in the "Turtle" "table_row" And I set the field "New name for tag Turtle" to "DOG" - And I press key "13" in the field "New name for tag Turtle" + And I press the enter key And I should see "The tag name is already in use. Do you want to combine these tags?" And I press "Yes" Then I should not see "Turtle" And I should not see "DOG" And I should see "Dog" - And I log out @javascript Scenario: Combining multiple tags @@ -232,7 +225,6 @@ Feature: Users can edit tags to add description or rename And I should see "Turtle" # Even though Turtle was not standard but at least one of combined tags was (Neverusedtag). Now Turtle is also standard. And "Remove from standard tags" "link" should exist in the "Turtle" "table_row" - And I log out Scenario: Filtering tags When I log in as "manager1" @@ -249,4 +241,3 @@ Feature: Users can edit tags to add description or rename And I should see "Dog" And I should see "Cat" And I should see "Turtle" - And I log out diff --git a/user/tests/behat/edit_user_roles.feature b/user/tests/behat/edit_user_roles.feature index 90ff654358c..dbf1130c853 100644 --- a/user/tests/behat/edit_user_roles.feature +++ b/user/tests/behat/edit_user_roles.feature @@ -27,7 +27,7 @@ Feature: Edit user roles And I click on "Student 1's role assignments" "link" And I click on ".form-autocomplete-downarrow" "css_element" in the "student1" "table_row" And I click on "Non-editing teacher" item in the autocomplete list - And I press key "27" in the field "Student 1's role assignments" + And I press the escape key When I click on "Save changes" "link" Then I should see "Student, Non-editing teacher" in the "Student 1" "table_row" @@ -38,6 +38,6 @@ Feature: Edit user roles And I navigate to course participants And I click on "Student 1's role assignments" "link" And I click on ".form-autocomplete-selection [aria-selected=true]" "css_element" - And I press key "27" in the field "Student 1's role assignments" + And I press the escape key When I click on "Save changes" "link" Then I should see "No roles" in the "Student 1" "table_row" diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 9ebe633114d..e962dfcb416 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -238,7 +238,7 @@ Feature: Course participants can be filtered And I navigate to course participants And I click on "Student 1's role assignments" "link" And I click on ".form-autocomplete-selection [aria-selected=true]" "css_element" - And I press key "27" in the field "Student 1's role assignments" + And I press the escape key And I click on "Save changes" "link" And I set the field "type" in the "Filter 1" "fieldset" to "Roles" And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 1" "fieldset" @@ -350,7 +350,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 3" "fieldset" to "Any" And I set the field "type" in the "Filter 3" "fieldset" to "Keyword" And I set the field "Type..." to "teacher1" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 2" in the "participants" "table" And I should see "Student 4" in the "participants" "table" @@ -396,7 +396,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 3" "fieldset" to "Any" And I set the field "type" in the "Filter 3" "fieldset" to "Keyword" And I set the field "Type..." to "3@" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 1" in the "participants" "table" And I should not see "Student 2" in the "participants" "table" @@ -419,7 +419,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 1" "fieldset" to "Any" And I set the field "type" in the "Filter 1" "fieldset" to "Keyword" And I set the field "Type..." to "1@example" - And I press key "13" in the field "Type..." + And I press the enter key When I click on "Apply filters" "button" Then I should see "Student 1" in the "participants" "table" And I should see "Teacher 1" in the "participants" "table" @@ -449,7 +449,7 @@ Feature: Course participants can be filtered And I should not see "Teacher 1" in the "participants" "table" # Add a second keyword filter value And I set the field "Type..." to "moodle" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 2" in the "participants" "table" And I should see "Student 3" in the "participants" "table" @@ -534,7 +534,7 @@ Feature: Course participants can be filtered And I set the field "type" in the "Filter 1" "fieldset" to "Keyword" # Search by email (only). And I set the field "Type..." to "student1@example.com" - And I press key "13" in the field "Type..." + And I press the enter key When I click on "Apply filters" "button" Then I should see "Student 1" in the "participants" "table" And I should not see "Student 2" in the "participants" "table" @@ -542,7 +542,7 @@ Feature: Course participants can be filtered # Search by idnumber (only). And I click on "student1@example.com" "autocomplete_selection" And I set the field "Type..." to "SID" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 1" in the "participants" "table" And I should see "Student 2" in the "participants" "table" @@ -552,7 +552,7 @@ Feature: Course participants can be filtered # Search by city (only). And I click on "SID" "autocomplete_selection" And I set the field "Type..." to "SCITY" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 1" in the "participants" "table" And I should see "Student 2" in the "participants" "table" @@ -562,13 +562,13 @@ Feature: Course participants can be filtered # Search by country text (only) - should not match. And I click on "SCITY" "autocomplete_selection" And I set the field "Type..." to "GB" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Nothing to display" # Check no match. And I click on "GB" "autocomplete_selection" And I set the field "Type..." to "NOTHING" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Nothing to display" @@ -586,7 +586,7 @@ Feature: Course participants can be filtered # Search by email (only) - should only see visible email + own. And I set the field "type" in the "Filter 1" "fieldset" to "Keyword" And I set the field "Type..." to "@example." - And I press key "13" in the field "Type..." + And I press the enter key When I click on "Apply filters" "button" Then I should not see "Student 1" in the "participants" "table" And I should see "Student 2" in the "participants" "table" @@ -596,25 +596,25 @@ Feature: Course participants can be filtered # Search for other fields - should only see own results. And I click on "@example." "autocomplete_selection" And I set the field "Type..." to "SID" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Nothing to display" And I click on "SID" "autocomplete_selection" And I set the field "Type..." to "TID" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Teacher 1" in the "participants" "table" And I should not see "Student 1" in the "participants" "table" And I click on "TID" "autocomplete_selection" And I set the field "Type..." to "CITY" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Teacher 1" in the "participants" "table" And I should not see "Student 1" in the "participants" "table" # Check no match. And I click on "CITY" "autocomplete_selection" And I set the field "Type..." to "NOTHING" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Nothing to display" @@ -633,7 +633,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 2" "fieldset" to "Any" And I set the field "type" in the "Filter 2" "fieldset" to "Keyword" And I set the field "Type..." to "@example" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 1" in the "participants" "table" And I should see "Student 2" in the "participants" "table" @@ -662,7 +662,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 2" "fieldset" to "Any" And I set the field "type" in the "Filter 2" "fieldset" to "Keyword" And I set the field "Type..." to "@example" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Apply filters" "button" And I should see "Student 1" in the "participants" "table" And I should see "Student 2" in the "participants" "table" @@ -684,7 +684,7 @@ Feature: Course participants can be filtered And I set the field "Match" in the "Filter 1" "fieldset" to "Any" And I set the field "type" in the "Filter 1" "fieldset" to "Keyword" And I set the field "Type..." to "@example.com" - And I press key "13" in the field "Type..." + And I press the enter key And I click on "Add condition" "button" # Set filterset to match none. And I set the field "Match" to "None" From bce0d4b80ff8384f314de334a72f764474cde245 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 23 Jun 2020 11:09:58 +0800 Subject: [PATCH 3/4] MDL-70148 qtype: Update qtype steps to new key interaction Note: The ddmarker question type was previously getting the number of keypresses wrong. This was because it was using both keyDown/keyUp, and also keyPress. As a result each keypress was essentially happening two times. --- .../tests/behat/behat_qtype_ddimageortext.php | 6 +++--- .../ddmarker/tests/behat/behat_qtype_ddmarker.php | 11 ++--------- question/type/ddmarker/tests/behat/preview.feature | 4 ++-- .../type/ddwtos/tests/behat/behat_qtype_ddwtos.php | 5 ++--- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php b/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php index ced73dcacf5..d2fc17d5ed6 100644 --- a/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php +++ b/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php @@ -80,10 +80,10 @@ class behat_qtype_ddimageortext extends behat_base { public function i_type_on_place_in_the_drag_and_drop_onto_image_question($keys, $placenumber) { $node = $this->get_selected_node('xpath_element', $this->drop_xpath($placenumber)); $this->ensure_node_is_visible($node); + + $node->focus(); foreach (str_split($keys) as $key) { - $node->keyDown($key); - $node->keyPress($key); - $node->keyUp($key); + behat_base::type_keys($this->getSession(), [$key]); $this->wait_for_pending_js(); } } diff --git a/question/type/ddmarker/tests/behat/behat_qtype_ddmarker.php b/question/type/ddmarker/tests/behat/behat_qtype_ddmarker.php index 9a74a1373e5..c90480aaccf 100644 --- a/question/type/ddmarker/tests/behat/behat_qtype_ddmarker.php +++ b/question/type/ddmarker/tests/behat/behat_qtype_ddmarker.php @@ -103,18 +103,11 @@ class behat_qtype_ddmarker extends behat_base { * @Given /^I type "(?Pup|down|left|right)" "(?P\d+)" times on marker "(?P[^"]*)" in the drag and drop markers question$/ */ public function i_type_on_marker_in_the_drag_and_drop_markers_question($direction, $repeats, $marker) { - $keycodes = array( - 'up' => chr(38), - 'down' => chr(40), - 'left' => chr(37), - 'right' => chr(39), - ); $node = $this->get_selected_node('xpath_element', $this->marker_xpath($marker, true)); $this->ensure_node_is_visible($node); + $node->focus(); for ($i = 0; $i < $repeats; $i++) { - $node->keyDown($keycodes[$direction]); - $node->keyPress($keycodes[$direction]); - $node->keyUp($keycodes[$direction]); + $this->execute('behat_general::i_press_named_key', ['', $direction]); } } } diff --git a/question/type/ddmarker/tests/behat/preview.feature b/question/type/ddmarker/tests/behat/preview.feature index 560c688ecad..049dec2bda1 100644 --- a/question/type/ddmarker/tests/behat/preview.feature +++ b/question/type/ddmarker/tests/behat/preview.feature @@ -50,8 +50,8 @@ Feature: Preview a drag-drop marker question # Keep window large else drag will scroll the window to find element. And I change window size to "medium" And I wait "2" seconds - And I type "up" "44" times on marker "Railway station" in the drag and drop markers question - And I type "right" "13" times on marker "Railway station" in the drag and drop markers question + And I type "up" "88" times on marker "Railway station" in the drag and drop markers question + And I type "right" "26" times on marker "Railway station" in the drag and drop markers question And I press "Submit and finish" Then the state of "Please place the markers on the map of Milton Keynes" question is shown as "Partially correct" And I should see "Mark 0.25 out of 1.00" diff --git a/question/type/ddwtos/tests/behat/behat_qtype_ddwtos.php b/question/type/ddwtos/tests/behat/behat_qtype_ddwtos.php index f04131d13a1..c15dba07752 100644 --- a/question/type/ddwtos/tests/behat/behat_qtype_ddwtos.php +++ b/question/type/ddwtos/tests/behat/behat_qtype_ddwtos.php @@ -79,10 +79,9 @@ class behat_qtype_ddwtos extends behat_base { public function i_type_into_space_in_the_drag_and_drop_into_text_question($keys, $spacenumber) { $node = $this->get_selected_node('xpath_element', $this->drop_xpath($spacenumber)); $this->ensure_node_is_visible($node); + $node->focus(); foreach (str_split($keys) as $key) { - $node->keyDown($key); - $node->keyPress($key); - $node->keyUp($key); + behat_base::type_keys($this->getSession(), [$key]); $this->wait_for_pending_js(); } } From 3959958372bc7340961b10aaa07352a560645d79 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 9 Nov 2020 15:35:54 +0800 Subject: [PATCH 4/4] MDL-70148 gradereport_grader: Improve reliability of keyboard usage In some browsers the ajax grade select does not properly update the grade after setting values. The previous solution was to press the [enter] key, but doing this with the new key type step opens the select box again. This is what happens when a real user presses enter on the select. This is the last possible field in the report, so pressing the tab key to move to the next gradable element does not work. The solution uses a shift-tab to move the focus away to the previous gradale element. In this case it must also be moved to an earlier step because the previously selected value must be checked in the Then section of the test and if it is selected then its value cannot be checked. --- grade/report/grader/tests/behat/ajax_grader.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grade/report/grader/tests/behat/ajax_grader.feature b/grade/report/grader/tests/behat/ajax_grader.feature index 072c5f04cf1..3500be14ba0 100644 --- a/grade/report/grader/tests/behat/ajax_grader.feature +++ b/grade/report/grader/tests/behat/ajax_grader.feature @@ -62,15 +62,15 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe And I press the enter key And I should not see a grade field for "Student 2" and grade item "Item VU" And I should not see a feedback field for "Student 2" and grade item "Item VU" + And I click on student "Student 3" for grade item "Item SU" + And I set the field "ajaxgrade" to "Very good" + And I press the shift tab key And I click on student "Student 3" for grade item "Item VU" And I set the field "ajaxgrade" to "50" And I press the enter key And I click on student "Student 3" for grade item "Item 1" And I set the field "ajaxgrade" to "80" And I press the enter key - And I click on student "Student 3" for grade item "Item SU" - And I set the field "ajaxgrade" to "Very good" - And I press the enter key And the following should exist in the "user-grades" table: | -1- | -6- | -7- | -13- | -16- | | Student 2 | - | 33.00 | - | 33.00 |