Commit ac9ecf6b authored by jun's avatar jun
Browse files

MDL-70032 qtype_multichoice: Use custom partial named selector

* With the removal of the label element, Behat now has to click on the
answer text. In order to achieve this, the custom partial named selector
"qtype_multichoice > Answer" was now added and have replaced the
instances where the label of the answer's checkbox/radio button is
being clicked.
parent a1d81dc6
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Behat qtype_multichoice-related steps definitions.
*
* @package qtype_multichoice
* @category test
* @copyright 2020 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Behat custom step definitions and partial named selectors for qtype_multichoice.
*
* @package qtype_multichoice
* @category test
* @copyright 2020 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_qtype_multichoice extends behat_base {
/**
* Return the list of partial named selectors for this plugin.
*
* @return behat_component_named_selector[]
*/
public static function get_partial_named_selectors(): array {
return [
new behat_component_named_selector(
'Answer', [
<<<XPATH
.//div[@data-region='answer-label']//*[contains(text(), %locator%)]
XPATH
]
),
];
}
}
......@@ -44,7 +44,7 @@ Feature: Clear my answers
And I follow "Quiz 1"
And I press "Attempt quiz now"
And I should see "Question One"
And I click on "Four" "radio" in the "Question One" "question"
And I click on "Four" "qtype_multichoice > Answer" in the "Question One" "question"
And I should see "Clear my choice"
And I click on "Clear my choice" "button" in the "Question One" "question"
Then I should not see "Clear my choice"
......@@ -58,7 +58,7 @@ Feature: Clear my answers
And I follow "Quiz 1"
And I press "Attempt quiz now"
And I should see "Question One"
And I click on "Four" "radio" in the "Question One" "question"
And I click on "Four" "qtype_multichoice > Answer" in the "Question One" "question"
And I follow "Finish attempt ..."
And I click on "Return to attempt" "button"
And I click on "Clear my choice" "button" in the "Question One" "question"
......
......@@ -31,8 +31,8 @@ Feature: Preview a Multiple choice question
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I click on "One" "checkbox"
And I click on "Two" "checkbox"
And I click on "One" "qtype_multichoice > Answer"
And I click on "Two" "qtype_multichoice > Answer"
And I press "Check"
Then I should see "One is odd"
And I should see "Two is even"
......@@ -46,8 +46,8 @@ Feature: Preview a Multiple choice question
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I click on "One" "checkbox"
And I click on "Three" "checkbox"
And I click on "One" "qtype_multichoice > Answer"
And I click on "Three" "qtype_multichoice > Answer"
And I press "Check"
Then I should see "One is odd"
And I should see "Three is odd"
......@@ -63,7 +63,7 @@ Feature: Preview a Multiple choice question
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I click on "One" "radio"
And I click on "One" "qtype_multichoice > Answer"
And I press "Check"
Then I should see "The oddest number is One."
And I should see "Mark 1.00 out of 1.00"
......@@ -77,7 +77,7 @@ Feature: Preview a Multiple choice question
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I click on "One" "radio"
And I click on "One" "qtype_multichoice > Answer"
Then I should see "Clear my choice"
And I click on "Clear my choice" "text"
And I should not see "Clear my choice"
......
This file describes API changes in /question/type/multichoice/*.
=== 3.9.3 ===
* The label for the multiple choice answers are being removed and the inputs (radio buttons/checkboxes) are now being labelled
by the answer texts via the aria-labelledby attribute. Because of this, Behat steps that used to click on the labels for the
multiple choice answer such as
And I click on "One" "checkbox"
won't work anymore. This has been replaced by having Behat click on the answer text using the custom partial named selector
"qtype_multichoice > Answer". So the above behat step would now be
And I click on "One" "qtype_multichoice > Answer"
This applies to both single-answer and multiple-answer multiple choice question types.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment