From 380ab95f20103b22b67db85c904c62bd3353a195 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 21 Jan 2016 13:44:58 +0800 Subject: [PATCH] MDL-52839 behat: Fixed xpath and wait to ensure element is visible --- course/tests/behat/behat_course.php | 23 +++++++++++-------- .../editpdf/tests/behat/annotate_pdf.feature | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index ffe7470019a..e0ba5c115a1 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -215,6 +215,9 @@ class behat_course extends behat_base { throw new DriverException('Section edit menu not available when Javascript is disabled'); } + // Wait for section to be available, before clicking on the menu. + $this->i_wait_until_section_is_available($sectionnumber); + // If it is already opened we do nothing. $xpath = $this->section_exists($sectionnumber); $xpath .= "/descendant::div[contains(@class, 'section-actions')]/descendant::a[contains(@class, 'textmenu')]"; @@ -300,6 +303,11 @@ class behat_course extends behat_base { */ public function i_show_section($sectionnumber) { $showlink = $this->show_section_icon_exists($sectionnumber); + + // Ensure section edit menu is open before interacting with it. + if ($this->running_javascript()) { + $this->i_open_section_edit_menu($sectionnumber); + } $showlink->click(); if ($this->running_javascript()) { @@ -316,6 +324,11 @@ class behat_course extends behat_base { */ public function i_hide_section($sectionnumber) { $hidelink = $this->hide_section_icon_exists($sectionnumber); + + // Ensure section edit menu is open before interacting with it. + if ($this->running_javascript()) { + $this->i_open_section_edit_menu($sectionnumber); + } $hidelink->click(); if ($this->running_javascript()) { @@ -964,11 +977,6 @@ class behat_course extends behat_base { // We need to know the course format as the text strings depends on them. $courseformat = $this->get_course_format(); - // If javascript is on, link is inside a menu. - if ($this->running_javascript()) { - $this->i_open_section_edit_menu($sectionnumber); - } - // Checking the show button alt text and show icon. $showtext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('showfromothers', $courseformat)); $linkxpath = $xpath . "/descendant::a[@title=$showtext]"; @@ -996,11 +1004,6 @@ class behat_course extends behat_base { // We need to know the course format as the text strings depends on them. $courseformat = $this->get_course_format(); - // If javascript is on, link is inside a menu. - if ($this->running_javascript()) { - $this->i_open_section_edit_menu($sectionnumber); - } - // Checking the hide button alt text and hide icon. $hidetext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('hidefromothers', $courseformat)); $linkxpath = $xpath . "/descendant::a[@title=$hidetext]"; diff --git a/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature b/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature index c1dfa7ad70e..36e37651151 100644 --- a/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature +++ b/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature @@ -60,7 +60,7 @@ Feature: In an assignment, teacher can annotate PDF files during grading And I click on ".stampbutton" "css_element" And I click on ".linebutton" "css_element" And I click on ".commentcolourbutton" "css_element" - And I click on "//img[@alt=\"Blue\"]" "xpath_element" + And I click on "//img[@alt=\"Blue\"]/parent::button" "xpath_element" And I change window size to "medium" And I wait until the page is ready And I click on "Close" "button" -- 2.43.0