Merge pull request #3580 from NoelDeMartin/MOBILE-4270-quiz

MOBILE-4270: Test additional question types
main
Dani Palou 2023-03-28 09:38:18 +02:00 committed by GitHub
commit 61809c06c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 30 deletions

View File

@ -34,17 +34,28 @@ Feature: Attempt a quiz in app
| activity | name | intro | course | idnumber |
| quiz | Quiz 2 | Quiz 2 description | C1 | quiz2 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions 2|
| contextlevel | reference | name |
| Course | C1 | Test questions 2 |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | multichoice | TF3 | Text of the first question |
| Test questions | shortanswer | TF4 | Text of the second question |
| Test questions | numerical | TF5 | Text of the third question |
| Test questions | essay | TF6 | Text of the fourth question |
| questioncategory | qtype | name | questiontext |
| Test questions | multichoice | TF3 | Text of the first question |
| Test questions | shortanswer | TF4 | Text of the second question |
| Test questions | numerical | TF5 | Text of the third question |
| Test questions | essay | TF6 | Text of the fourth question |
| Test questions | ddwtos | TF7 | The [[1]] brown [[2]] jumped over the [[3]] dog. |
| Test questions | truefalse | TF8 | Text of the sixth question |
| Test questions | match | TF9 | Text of the seventh question |
| Test questions | truefalse | TF8 | Text of the sixth question |
| Test questions | match | TF9 | Text of the seventh question |
| Test questions | description | TF10 | Text of the eighth question |
# TODO test calculated question type.
# TODO test multianswer question type.
# The calculatedsimple type is implemented using the calculated type.
# The calculatedmulti type is implemented using the multichoice type.
# The randomsamatch type is implemented using the match type.
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | gapselect | TF11 | missingchoiceno |
| Test questions | ddimageortext | TF12 | xsection |
| Test questions | ddmarker | TF13 | mkmap |
And quiz "Quiz 2" contains the following questions:
| question | page |
| TF3 | 1 |
@ -54,6 +65,10 @@ Feature: Attempt a quiz in app
| TF7 | 5 |
| TF8 | 6 |
| TF9 | 7 |
| TF10 | 8 |
| TF11 | 9 |
| TF12 | 10 |
| TF13 | 11 |
Scenario: View a quiz entry page (attempts, status, etc.)
Given I entered the quiz activity "Quiz 1" on course "Course 1" as "student1" in the app
@ -117,11 +132,11 @@ Feature: Attempt a quiz in app
And I set the field "Answer" to "Testing an essay" in the app
And I press "Next" "ion-button" in the app
And I press "quick" ".drag" in the app
And I press "" ".place1.drop" in the app
And I click on ".place1.drop" "css"
And I press "fox" ".drag" in the app
And I press "" ".place2.drop" in the app
And I click on ".place2.drop" "css"
And I press "lazy" ".drag" in the app
And I press "" ".place3.drop" in the app
And I click on ".place3.drop" "css"
And I press "Next" in the app
And I press "True" in the app
And I press "Next" in the app
@ -131,8 +146,24 @@ Feature: Attempt a quiz in app
And I press "insect" in the app
And I press "Choose... , cat" in the app
And I press "mammal" in the app
And I press "Next" in the app
Then I should find "Text of the eighth question" in the app
When I press "Next" in the app
And I set the field "Blank 1" to "cat" in the app
And I set the field "Blank 2" to "mat" in the app
And I press "Next" in the app
And I press "abyssal" ".drag" in the app
And I click on ".place6.dropzone" "css"
And I press "trench" ".drag" in the app
And I click on ".place3.dropzone" "css"
And I press "Next" in the app
And I press "Railway station" ".marker" in the app
And I click on "img.dropbackground" "css"
And I press "Submit" in the app
Then I should not find "Not yet answered" in the app
Then I should find "Answer saved" in the app
And I should find "Incomplete answer" within "9" "ion-item" in the app
But I should not find "Not yet answered" in the app
When I press "Submit all and finish" in the app
And I press "OK" in the app

View File

@ -384,6 +384,34 @@ export class TestingBehatDomUtilsService {
return topContainers;
}
/**
* Find a field.
*
* @param field Field name.
* @returns Field element.
*/
findField(field: string): HTMLElement | HTMLInputElement | undefined {
const input = this.findElementBasedOnText(
{ text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime' },
{ onlyClickable: false, containerName: '' },
);
if (input) {
return input;
}
const label = this.findElementBasedOnText(
{ text: field, selector: 'label' },
{ onlyClickable: false, containerName: '' },
);
if (label) {
const inputId = label.getAttribute('for');
return (inputId && document.getElementById(inputId)) || undefined;
}
}
/**
* Function to find element based on their text or Aria label.
*

View File

@ -422,13 +422,22 @@ export class TestingBehatRuntimeService {
async setField(field: string, value: string): Promise<string> {
this.log('Action - Set field ' + field + ' to: ' + value);
const found = this.findField(field);
const input = TestingBehatDomUtils.findField(field);
if (!found) {
if (!input) {
return 'ERROR: No element matches field to set.';
}
await TestingBehatDomUtils.setElementValue(found, value);
if (input instanceof HTMLSelectElement) {
const options = Array.from(input.querySelectorAll('option'));
value = options.find(option => option.value === value)?.value
?? options.find(option => option.text === value)?.value
?? options.find(option => option.text.includes(value))?.value
?? value;
}
await TestingBehatDomUtils.setElementValue(input, value);
return 'OK';
}
@ -445,7 +454,7 @@ export class TestingBehatRuntimeService {
async fieldMatches(field: string, value: string): Promise<string> {
this.log('Action - Field ' + field + ' matches value: ' + value);
const found = this.findField(field);
const found = TestingBehatDomUtils.findField(field);
if (!found) {
return 'ERROR: No element matches field to set.';
@ -459,19 +468,6 @@ export class TestingBehatRuntimeService {
return 'OK';
}
/**
* Find a field.
*
* @param field Field name.
* @returns Field element.
*/
protected findField(field: string): HTMLElement | HTMLInputElement | undefined {
return TestingBehatDomUtils.findElementBasedOnText(
{ text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime' },
{ onlyClickable: false, containerName: '' },
);
}
/**
* Get the value of a certain field.
*