From fba0ac63b88dbdbfc3841f4bc873431f6e12e3c9 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 9 Jun 2016 08:26:50 +0800 Subject: [PATCH] MDL-54589 behat: Added hack for some OS/browsers --- .../grader/tests/behat/ajax_grader.feature | 3 ++- lib/behat/form_field/behat_form_select.php | 25 +++++++++++++------ lib/tests/behat/behat_general.php | 18 +++++++++++++ .../editpdf/tests/behat/annotate_pdf.feature | 1 + .../tests/behat/group_annotations.feature | 2 ++ mod/quiz/tests/behat/attempt_begin.feature | 4 +++ 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/grade/report/grader/tests/behat/ajax_grader.feature b/grade/report/grader/tests/behat/ajax_grader.feature index d341ffdd0d9..b60f4643197 100644 --- a/grade/report/grader/tests/behat/ajax_grader.feature +++ b/grade/report/grader/tests/behat/ajax_grader.feature @@ -47,7 +47,8 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe And the following config values are set as admin: | grade_report_showaverages | 0 | | grade_report_enableajax | 1 | - + # Floating headers can fail to set value on some OS/Browsers, so do this test on large screens. + And I change window size to "large" @javascript Scenario: Use the grader report without editing, with AJAX on and quick feedback off diff --git a/lib/behat/form_field/behat_form_select.php b/lib/behat/form_field/behat_form_select.php index 4f7a34f3d06..0b16552bb72 100644 --- a/lib/behat/form_field/behat_form_select.php +++ b/lib/behat/form_field/behat_form_select.php @@ -71,15 +71,24 @@ class behat_form_select extends behat_form_field { // Wait for all the possible AJAX requests that have been // already triggered by selectOption() to be finished. if ($this->running_javascript()) { - // Trigger change event as this is needed by some drivers (Phantomjs, Mac-FF). Don't do it for - // Singleselect as this will cause multiple event fire and lead to race-around condition. + // Trigger change event and click on first skip link, as some OS/browsers (Phantomjs, Mac-FF), + // don't close select option field and trigger event. if (!$singleselect) { - $script = "Syn.trigger('change', {}, {{ELEMENT}})"; - try { - $this->session->getDriver()->triggerSynScript($this->field->getXpath(), $script); - } catch (Exception $e) { - // No need to do anything if element has been removed by JS. - // This is possible when inline editing element is used. + $dialoguexpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-focused ')]"; + if (!$node = $this->session->getDriver()->find($dialoguexpath)) { + $script = "Syn.trigger('change', {}, {{ELEMENT}})"; + try { + $this->session->getDriver()->triggerSynScript($this->field->getXpath(), $script); + $this->session->getDriver()->click('//body//div[@class="skiplinks"]'); + } catch (\Exception $e) { + return; + } + } else { + try { + $this->session->getDriver()->click($dialoguexpath); + } catch (\Exception $e) { + return; + } } } $this->session->wait(behat_base::TIMEOUT * 1000, behat_base::PAGE_READY_JS); diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 46ce3ef9aea..07bf1136061 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1539,4 +1539,22 @@ class behat_general extends behat_base { $node->keyPress($char, $modifier); $node->keyUp($char, $modifier); } + + /** + * Press tab key on a specific element. + * + * @When /^I press tab key in "(?P(?:[^"]|\\")*)" "(?P[^"]*)"$/ + * @param string $element Element we look for + * @param string $selectortype The type of what we look for + * @throws DriverException + * @throws ExpectationException + */ + public function i_post_tab_key_in_element($element, $selectortype) { + if (!$this->running_javascript()) { + throw new DriverException('Tab press step is not available with Javascript disabled'); + } + // Gets the node based on the requested selector type and locator. + $node = $this->get_selected_node($selectortype, $element); + $this->getSession()->getDriver()->post_key("\xEE\x80\x84", $node->getXpath()); + } } diff --git a/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature b/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature index 9cab348cf75..98c0a3aca45 100644 --- a/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature +++ b/mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature @@ -129,6 +129,7 @@ Feature: In an assignment, teacher can annotate PDF files during grading And I follow "View all submissions" And I click on "Edit" "link" in the "Student 2" "table_row" And I click on "Grade" "link" in the "Student 2" "table_row" + And I wait until the page is ready And I click on ".linebutton" "css_element" And I draw on the pdf And I press "Save changes" diff --git a/mod/assign/feedback/editpdf/tests/behat/group_annotations.feature b/mod/assign/feedback/editpdf/tests/behat/group_annotations.feature index 4292b101855..787bd4e6752 100644 --- a/mod/assign/feedback/editpdf/tests/behat/group_annotations.feature +++ b/mod/assign/feedback/editpdf/tests/behat/group_annotations.feature @@ -51,7 +51,9 @@ Feature: In a group assignment, teacher can annotate PDF files for all users And I follow "Test assignment name" And I follow "View all submissions" And I click on "Grade" "link" in the "Submitted for grading" "table_row" + And I wait until the page is ready And I click on ".navigate-next-button" "css_element" + And I wait until the page is ready And I click on ".stampbutton" "css_element" And I draw on the pdf And I wait until the page is ready diff --git a/mod/quiz/tests/behat/attempt_begin.feature b/mod/quiz/tests/behat/attempt_begin.feature index a2987a8eacc..4561c02f1de 100644 --- a/mod/quiz/tests/behat/attempt_begin.feature +++ b/mod/quiz/tests/behat/attempt_begin.feature @@ -88,6 +88,8 @@ Feature: The various checks that may happen when an attept is started And I should see "The quiz has a time limit of 1 hour. Time will " And I should see "The password entered was incorrect" And I set the field "Quiz password" to "Frog" + # On Mac/FF tab key is needed as text field in dialogue and page have same id. + And I press tab key in "Quiz password" "field" And I press "Start attempt" And I should see "Text of the first question" @@ -110,6 +112,8 @@ Feature: The various checks that may happen when an attept is started And I should see "The quiz has a time limit of 1 hour. Time will " And I should see "The password entered was incorrect" And I set the field "Quiz password" to "Frog" + # On Mac/FF tab key is needed as text field in dialogue and page have same id. + And I press tab key in "Quiz password" "field" And I press "Cancel" Then I should see "Quiz 1 description" And "Attempt quiz now" "button" should be visible