diff --git a/admin/tool/lp/tests/behat/behat_tool_lp.php b/admin/tool/lp/tests/behat/behat_tool_lp.php index a43d857ff68..acd0b19d2a3 100644 --- a/admin/tool/lp/tests/behat/behat_tool_lp.php +++ b/admin/tool/lp/tests/behat/behat_tool_lp.php @@ -63,16 +63,4 @@ class behat_tool_lp extends behat_base { $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']); } - /** - * Select item from autocomplete list. - * - * @Given /^I click on "([^"]*)" item in the autocomplete list$/ - * - * @param string $item - */ - public function i_click_on_item_in_the_autocomplete_list($item) { - $xpathtarget = "//ul[@class='form-autocomplete-suggestions']//li//span//span[contains(.,'" . $item . "')]"; - - $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']); - } } diff --git a/admin/tool/lp/tests/behat/plan_crud.feature b/admin/tool/lp/tests/behat/plan_crud.feature index 31b8d2d9160..7e9fecc0cf6 100644 --- a/admin/tool/lp/tests/behat/plan_crud.feature +++ b/admin/tool/lp/tests/behat/plan_crud.feature @@ -28,7 +28,7 @@ Feature: Manage plearning plan And I follow "Home" And I navigate to "Competencies > Learning plan templates" in site administration And I click on ".template-userplans" "css_element" in the "Science template" "table_row" - And I click on ".form-autocomplete-downarrow" "css_element" + And I open the autocomplete suggestions list And I click on "Admin" item in the autocomplete list And I press key "27" in the field "Select users to create learning plans for" When I click on "Create learning plans" "button" diff --git a/enrol/tests/behat/add_to_group.feature b/enrol/tests/behat/add_to_group.feature index c5fdca1ab48..bdaf1bca1db 100644 --- a/enrol/tests/behat/add_to_group.feature +++ b/enrol/tests/behat/add_to_group.feature @@ -28,10 +28,10 @@ Feature: Users can be added to multiple groups at once And I am on "Course 1" course homepage And I follow "Participants" And I click on "Edit groups for \"Student 1\"" "link" in the "student1" "table_row" - And I click on ".form-autocomplete-downarrow" "css_element" - And I click on ".form-autocomplete-suggestions [role=option]" "css_element" - And I click on ".form-autocomplete-downarrow" "css_element" - And I click on ".form-autocomplete-suggestions [role=option]" "css_element" + And I open the autocomplete suggestions list + And I click on "Group 1" item in the autocomplete list + And I open the autocomplete suggestions list + And I click on "Group 2" item in the autocomplete list And I click on "Save changes" "link" Then I should see "Group 1, Group 2" diff --git a/lib/behat/behat_field_manager.php b/lib/behat/behat_field_manager.php index 3c770bbe379..b98f843799b 100644 --- a/lib/behat/behat_field_manager.php +++ b/lib/behat/behat_field_manager.php @@ -293,5 +293,4 @@ class behat_field_manager { return self::get_field_node_type($fieldnode, $session); } - } diff --git a/lib/behat/form_field/behat_form_autocomplete.php b/lib/behat/form_field/behat_form_autocomplete.php index aadfbc1e83b..2453d7abc24 100644 --- a/lib/behat/form_field/behat_form_autocomplete.php +++ b/lib/behat/form_field/behat_form_autocomplete.php @@ -54,5 +54,6 @@ class behat_form_autocomplete extends behat_form_text { $id = $this->field->getAttribute('id'); $js = ' require(["jquery"], function($) { $(document.getElementById("'.$id.'")).trigger("behat:set-value"); }); '; $this->session->executeScript($js); + $this->key_press(27); } } diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index f7e09b373bb..20593387c7e 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -524,4 +524,29 @@ class behat_forms extends behat_base { } } + /** + * Select item from autocomplete list. + * + * @Given /^I click on "([^"]*)" item in the autocomplete list$/ + * + * @param string $item + */ + public function i_click_on_item_in_the_autocomplete_list($item) { + $xpathtarget = "//ul[@class='form-autocomplete-suggestions']//*[contains(.,'" . $item . "')]"; + + $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']); + + $this->execute('behat_general::i_press_key_in_element', ['13', 'body', 'xpath_element']); + } + + /** + * Open the auto-complete suggestions list (Assuming there is only one on the page.). + * + * @Given /^I open the autocomplete suggestions list$/ + */ + public function i_open_the_autocomplete_suggestions_list() { + $csstarget = ".form-autocomplete-downarrow"; + $this->execute('behat_general::i_click_on', [$csstarget, 'css_element']); + } + } diff --git a/mod/book/tests/behat/edit_tags.feature b/mod/book/tests/behat/edit_tags.feature index 259b1e9b210..8a2348288fd 100644 --- a/mod/book/tests/behat/edit_tags.feature +++ b/mod/book/tests/behat/edit_tags.feature @@ -54,7 +54,7 @@ Feature: Edited book chapters handle tags correctly And I log in as "teacher1" And I am on "Course 1" course homepage And I follow "Test book" - And I click on ".form-autocomplete-downarrow" "css_element" + And I open the autocomplete suggestions list And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element" diff --git a/mod/forum/tests/behat/edit_tags.feature b/mod/forum/tests/behat/edit_tags.feature index d7c70588bc0..fd43824933e 100644 --- a/mod/forum/tests/behat/edit_tags.feature +++ b/mod/forum/tests/behat/edit_tags.feature @@ -52,7 +52,7 @@ Feature: Edited forum posts handle tags correctly And I follow "Test forum" And I click on "Add a new discussion topic" "button" And I expand all fieldsets - And I click on ".form-autocomplete-downarrow" "css_element" + And I open the autocomplete suggestions list And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element" diff --git a/mod/glossary/tests/behat/edit_tags.feature b/mod/glossary/tests/behat/edit_tags.feature index d4461c17eba..61d7c659579 100644 --- a/mod/glossary/tests/behat/edit_tags.feature +++ b/mod/glossary/tests/behat/edit_tags.feature @@ -56,7 +56,7 @@ Feature: Edited glossary entries handle tags correctly And I follow "Test glossary" And I press "Add a new entry" And I expand all fieldsets - And I click on ".form-autocomplete-downarrow" "css_element" + And I open the autocomplete suggestions list And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element" diff --git a/mod/wiki/tests/behat/edit_tags.feature b/mod/wiki/tests/behat/edit_tags.feature index ab60aab37f5..9fe515ab28f 100644 --- a/mod/wiki/tests/behat/edit_tags.feature +++ b/mod/wiki/tests/behat/edit_tags.feature @@ -56,7 +56,7 @@ Feature: Edited wiki pages handle tags correctly And I am on "Course 1" course homepage And I follow "Test wiki name" And I press "Create page" - And I click on ".form-autocomplete-downarrow" "css_element" + And I open the autocomplete suggestions list And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element" And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"