From c4fa89d55afee422d66750d46db5bdab5d9c2c37 Mon Sep 17 00:00:00 2001 From: Anupama Sarjoshi Date: Mon, 22 Mar 2021 16:07:33 +0000 Subject: [PATCH] MDL-71172 quiz: Improve quiz Behat tests --- mod/quiz/tests/behat/attempt_basic.feature | 26 ++++++++++++++++--- .../editing_add_from_question_bank.feature | 22 ++++++++++++++++ .../tests/behat/editing_add_random.feature | 11 ++++++++ mod/quiz/tests/behat/preview.feature | 9 ++++++- 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/mod/quiz/tests/behat/attempt_basic.feature b/mod/quiz/tests/behat/attempt_basic.feature index f946e525495..70dde156e0f 100644 --- a/mod/quiz/tests/behat/attempt_basic.feature +++ b/mod/quiz/tests/behat/attempt_basic.feature @@ -22,7 +22,7 @@ Feature: Attempt a quiz | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | @javascript - Scenario: Attempt a quiz with a single unnamed section + Scenario: Attempt a quiz with a single unnamed section, review and re-attempt Given the following "questions" exist: | questioncategory | qtype | name | questiontext | | Test questions | truefalse | TF1 | First question | @@ -37,7 +37,15 @@ Feature: Attempt a quiz | 2 | False | When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" And I follow "Review" - Then I should see "25.00 out of 100.00" + Then I should see "Started on" + And I should see "State" + And I should see "Completed on" + And I should see "Time taken" + And I should see "Marks" + And I should see "Grade" + And I should see "25.00 out of 100.00" + And I follow "Finish review" + And I press "Re-attempt quiz" @javascript Scenario: Attempt a quiz with mulitple sections @@ -59,10 +67,10 @@ Feature: Attempt a quiz | TF6 | 4 | And quiz "Quiz 1" contains the following sections: | heading | firstslot | shuffle | - | Section 1 | 1 | 1 | + | Section 1 | 1 | 0 | | Section 2 | 3 | 0 | | | 4 | 1 | - | Section 3 | 5 | 0 | + | Section 3 | 5 | 1 | When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" And I press "Attempt quiz now" @@ -95,6 +103,16 @@ Feature: Attempt a quiz And I should see question "5" in section "Section 3" in the quiz navigation And I should see question "6" in section "Section 3" in the quiz navigation + And I follow "Show one page at a time" + And I should see "First question" + And I should not see "Third question" + And I should see "Next page" + + And I follow "Show all questions on one page" + And I should see "Fourth question" + And I should see "Sixth question" + And I should not see "Next page" + @javascript Scenario: Next and previous navigation Given the following "questions" exist: diff --git a/mod/quiz/tests/behat/editing_add_from_question_bank.feature b/mod/quiz/tests/behat/editing_add_from_question_bank.feature index 94b56cf13e8..68cf20ef9ef 100644 --- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature +++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature @@ -103,3 +103,25 @@ Feature: Adding questions to a quiz from the question bank And I click on "Add selected questions to the quiz" "button" Then I should see "question 03 name" on quiz page "1" And I should see "question 01 name" before "question 03 name" on the edit quiz page + + Scenario: Add several selected questions from the question bank + Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" + When I open the "last" add to quiz menu + And I follow "from question bank" + And I set the field with xpath "//input[@type='checkbox' and @id='qbheadercheckbox']" to "1" + And I press "Add selected questions to the quiz" + Then I should see "question 01 name" on quiz page "1" + And I should see "question 02 name" on quiz page "2" + + @javascript + Scenario: Validate the sorting while adding questions from question bank + Given the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | multichoice | question 03 name | question 03 name text | + And I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" + When I open the "last" add to quiz menu + And I follow "from question bank" + And I follow "Sort by Question type descending" + Then "question 03 name" "checkbox" should appear before "question 01 name" "checkbox" + And I follow "Sort by Question ascending" + And "question 01 name" "checkbox" should appear before "question 02 name" "checkbox" diff --git a/mod/quiz/tests/behat/editing_add_random.feature b/mod/quiz/tests/behat/editing_add_random.feature index d47e990c73c..1664cf02cbd 100644 --- a/mod/quiz/tests/behat/editing_add_random.feature +++ b/mod/quiz/tests/behat/editing_add_random.feature @@ -54,3 +54,14 @@ Feature: Adding random questions to a quiz based on category and tags And I am on the "Quiz 1" "mod_quiz > Edit" page When I open the "last" add to quiz menu Then I should not see "a random question" + + Scenario: A random question can be added to the quiz by creating a new category + Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" + When I open the "last" add to quiz menu + And I follow "a random question" + And I follow "New category" + And I set the following fields to these values: + | Name | New Random category | + | Parent category | Top for Quiz 1 | + And I press "Create category and add random question" + Then I should see "Random (New Random category)" on quiz page "1" diff --git a/mod/quiz/tests/behat/preview.feature b/mod/quiz/tests/behat/preview.feature index d8c8733bba7..f16980eb84a 100644 --- a/mod/quiz/tests/behat/preview.feature +++ b/mod/quiz/tests/behat/preview.feature @@ -34,9 +34,16 @@ Feature: Preview a quiz as a teacher | 2 | False | @javascript - Scenario: Preview a quiz + Scenario: Review the quiz attempt When I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher" And I follow "Review" Then I should see "25.00 out of 100.00" And I follow "Finish review" And "Review" "link" in the "Preview" "table_row" should be visible + + @javascript + Scenario: Preview the quiz + Given I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher" + When I press "Preview quiz now" + Then I should see "Question 1" + And "Start a new preview" "button" should exist