From 27d2eed0ec09f45640e2cddef8ce32d3a6794d0e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 28 Jul 2022 15:32:44 +0800 Subject: [PATCH 1/1] MDL-74655 example solution --- admin/tool/lp/tests/behat/behat_tool_lp.php | 37 ++++++++++++++++ .../tests/behat/view_competencies.feature | 44 ++++++++++--------- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/admin/tool/lp/tests/behat/behat_tool_lp.php b/admin/tool/lp/tests/behat/behat_tool_lp.php index acd0b19d2a..72ad1771fc 100644 --- a/admin/tool/lp/tests/behat/behat_tool_lp.php +++ b/admin/tool/lp/tests/behat/behat_tool_lp.php @@ -63,4 +63,41 @@ class behat_tool_lp extends behat_base { $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']); } + protected function resolve_page_instance_url(string $page, string $identifier): moodle_url { + switch (strtolower($page)) { + case 'course competencies': + $courseid = $this->get_course_id($identifier); + return new moodle_url('/admin/tool/lp/coursecompetencies.php', [ + 'courseid' => $courseid, + ]); + break; + default: + throw new Exception("Unrecognised page type '{$page}'"); + } + } + + /** + * Return a list of the exact named selectors for the component. + * + * @return behat_component_named_selector[] + */ + public static function get_exact_named_selectors(): array { + return [ + new behat_component_named_selector('competency', [ + "//table[contains(@class,'managecompetencies')]//tr[contains(., //a[@title='View details'][contains(., %locator%)])]", + ]), + new behat_component_named_selector('description', [ + "//p[contains(., %locator%)]", + ]), + new behat_component_named_selector('grade', [ + "//span[contains(concat(' ', normalize-space(@class), ' '), ' badge ')][contains(., %locator%)]", + ]), + new behat_component_named_selector('competency page proficiency', [ + "//dt[contains(., 'Proficient')]/following-sibling::dd[1][contains(., %locator%)]", + ]), + new behat_component_named_selector('competency page rating', [ + "//dt[contains(., 'Rating')]/following-sibling::dd[1][contains(., %locator%)]", + ]), + ]; + } } diff --git a/competency/tests/behat/view_competencies.feature b/competency/tests/behat/view_competencies.feature index 6c1bb16879..0346094495 100644 --- a/competency/tests/behat/view_competencies.feature +++ b/competency/tests/behat/view_competencies.feature @@ -62,31 +62,33 @@ Feature: Display competencies | C1 | cakes | student1 | Great | Scenario: Student view - Given I am on the "C1" "Course" page logged in as "student1" - - # Course competencies - When I navigate to course competencies + Given I am on the "C1" "tool_lp > course competencies" page logged in as "student1" Then I should see "You are proficient in 3 out of 5 competencies in this course" - And "Salads are important" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Salads')]" "xpath_element" - And "Good" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Salads')]" "xpath_element" - And "Desserts are important" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Desserts')]" "xpath_element" - And "Great" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Desserts')]" "xpath_element" - And "Cakes are important" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Cakes')]" "xpath_element" - And "Great" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Cakes')]" "xpath_element" - And "Reading is important" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Reading')]" "xpath_element" - And "Writing is important" "text" should exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Writing')]" "xpath_element" - And "Good" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Reading')]" "xpath_element" - And "Great" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Reading')]" "xpath_element" - And "Bad" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Reading')]" "xpath_element" - And "Good" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Writing')]" "xpath_element" - And "Great" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Writing')]" "xpath_element" - And "Bad" "text" should not exist in the "//table[contains(@class,'managecompetencies')]//tr[contains(., 'Writing')]" "xpath_element" + + And "Salads are important" "tool_lp > description" should exist in the "Salads" "tool_lp > competency" + And "Good" "tool_lp > grade" should exist in the "Salads" "tool_lp > competency" + + And "Desserts are important" "tool_lp > description" should exist in the "Desserts" "tool_lp > competency" + And "Great" "tool_lp > grade" should exist in the "Desserts" "tool_lp > competency" + + And "Cakes are important" "tool_lp > description" should exist in the "Cakes" "tool_lp > competency" + And "Great" "tool_lp > grade" should exist in the "Cakes" "tool_lp > competency" + + And "Reading is important" "tool_lp > description" should exist in the "Reading" "tool_lp > competency" + And "Good" "tool_lp > grade" should not exist in the "Reading" "tool_lp > competency" + And "Great" "tool_lp > grade" should not exist in the "Reading" "tool_lp > competency" + And "Bad" "tool_lp > grade" should not exist in the "Reading" "tool_lp > competency" + + And "Writing is important" "tool_lp > description" should exist in the "Writing" "tool_lp > competency" + And "Good" "tool_lp > grade" should not exist in the "Writing" "tool_lp > competency" + And "Great" "tool_lp > grade" should not exist in the "Writing" "tool_lp > competency" + And "Bad" "tool_lp > grade" should not exist in the "Writing" "tool_lp > competency" # Course competencies details - And I click on "Desserts" "link" + And I click on "Desserts" "link" in the "Desserts" "tool_lp > competency" And I should see "Desserts are important" - And "//dt[contains(., 'Proficient')]/following-sibling::dd[1][contains(.,'Yes')]" "xpath_element" should exist - And "//dt[contains(., 'Rating')]/following-sibling::dd[1][contains(.,'Great')]" "xpath_element" should exist + And "Yes" "tool_lp > competency page proficiency" should exist + And "Great" "tool_lp > competency page rating" should exist # Course competencies summary And I click on "Cakes" "link" -- 2.37.0