Skip to content

Commit

Permalink
MDL-79990 behat: custom step to verify assign grading data
Browse files Browse the repository at this point in the history
This commit also optimise the new behat test.
  • Loading branch information
lameze committed Mar 7, 2024
1 parent 87f413b commit 503cd95
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 56 deletions.
88 changes: 32 additions & 56 deletions grade/grading/form/guide/tests/behat/assign_marking_guide.feature
Expand Up @@ -21,8 +21,6 @@ Feature: Display marking guide information to students
| assign | C1 | Assign 1 | guide |
And I am on the "Course 1" course page logged in as teacher1
And I go to "Assign 1" advanced grading definition page
# Set default grading definition and marking guide.
# By default marking guide definition and marks per criterion are enabled.
And I set the following fields to these values:
| Name | Assign 1 marking guide |
| Description | Marking guide description |
Expand All @@ -32,65 +30,43 @@ Feature: Display marking guide information to students
| Grade Criteria 2 | Grade 2 description for students | Grade 2 description for markers | 30 |
And I press "Save marking guide and make it ready"


Scenario Outline: Confirm marking guide information display before student is graded
When I am on the "Assign 1" "assign activity" page logged in as student1
# Verify that criteria 1 and 2 name and description are displayed when student is logged in before being graded.
Then I should see "Grade Criteria <criteriacheck>" in the "#guide-criteria .criterion.<criteriaclass> .criterionshortname" "css_element"
And I should see "Grade <criteriacheck> description for students" in the "#guide-criteria .criterion.<criteriaclass> .criteriondescription" "css_element"

Examples:
|criteriacheck | criteriaclass |
| 1 | first |
| 2 | last |

Scenario Outline: Confirm that marking guide information is not displayed after student is graded
# Update the existing marking guide to ensure that marks per criterion is displayed.
Given I click on "Edit the current form definition" "link"
And I set the field "Show marks per criterion to students" to "0"
And I press "Save"
And I am on the "Assign 1" "assign activity" page
And I go to "Student 1" "Assign 1" activity advanced grading page
And I grade by filling the marking guide with:
| Grade Criteria 1 | 50 | Excellent work! |
| Grade Criteria 2 | 20 | Try harder |
And I press "Save changes"
When I am on the "Assign 1" "assign activity" page logged in as student1
# Confirm the marking guide information display after student is graded when marking per criterion display is disabled.
# Confirm that overall grade is displayed.
Then I should see "70.00 / 100.00" in the ".feedback .feedbacktable .generaltable .cell.c1.lastcol" "css_element"
# Verify that criteria 1 and 2 name, description and remark are displayed when marking per criterion display is disabled.
And I should see "Grade Criteria <criteriacheck>" in the "#guide0-criteria .criterion.<criteriaclass> .criterionshortname" "css_element"
And I should see "Grade <criteriacheck> description for students" in the "#guide-criteria .criterion.<criteriaclass> .criteriondescription" "css_element"
And I should see "<criteriaremark>" in the "#guide0-criteria .criterion.<criteriaclass> .remark" "css_element"

Examples:
| criteriacheck | criteriaclass | criteriaremark |
| 1 | first | Excellent work! |
| 2 | last | Try harder |

Scenario Outline: Confirm that marking guide information is displayed after student is graded
# No need to update marking guide as marking guide definition is already enabled by default
Given I am on the "Assign 1" "assign activity" page
Scenario: Confirm that marking guide information is not displayed after student is graded
# Update the existing marking guide to ensure that marks per criterion is displayed.
Given I click on "Edit the current form definition" "link"
And I set the field "Show marks per criterion to students" to "0"
And I press "Save"
And I am on the "Assign 1" "assign activity" page
And I go to "Student 1" "Assign 1" activity advanced grading page
And I grade by filling the marking guide with:
| Grade Criteria 1 | 50 | Excellent work! |
| Grade Criteria 2 | 20 | Try harder |
And I press "Save changes"
When I am on the "Assign 1" "assign activity" page logged in as student1
# Confirm the marking guide information display after student is graded when marking per criterion display is enabled.
# Confirm the marking guide information display after student is graded when marking per criterion display is disabled.
# Confirm that overall grade is displayed.
Then I should see "70.00 / 100.00" in the ".feedback .feedbacktable .generaltable .cell.c1.lastcol" "css_element"
# Confirm that criteria1 name is displayed.
# Confirm that all marking guide definition and marks per criterion are displayed.
# Verify that criteria 1 and 2 name, description, maximum score, remark and score are all displayed.
And I should see "Grade Criteria <criteriacheck>" in the "#guide0-criteria .criterion.<criteriaclass> .criterionshortname" "css_element"
And I should see "Grade <criteriacheck> description for students" in the "#guide-criteria .criterion.<criteriaclass> .criteriondescription" "css_element"
And I should see "<maxscore>" in the "#guide0-criteria .criterion.<criteriaclass> .criteriondescriptionscore" "css_element"
And I should see "<criteriaremark>" in the "#guide0-criteria .criterion.<criteriaclass> .remark" "css_element"
And I should see "<criteriascore>" in the "#guide0-criteria .criterion.<criteriaclass> .score" "css_element"
Then I should see "70.00 / 100.00"
And I should see the marking guide information displayed as:
| criteria | description | remark |
| Grade Criteria 1 | Grade 1 description for students | Excellent work! |
| Grade Criteria 2 | Grade 2 description for students | Try harder |

Examples:
| criteriacheck | criteriaclass | criteriaremark | maxscore | criteriascore |
| 1 | first | Excellent work! | 70 | 50 / 70 |
| 2 | last | Try harder | 30 | 20 / 30 |
Scenario: Confirm that marking guide information is displayed after student is graded
Given I am on the "Assign 1" "assign activity" page logged in as student1
And I should see "Grade 1 description for students" in the "Grade Criteria 1" "table_row"
And I should see "Grade 2 description for students" in the "Grade Criteria 2" "table_row"
# No grade to student1 yet.
And I should not see "70.00 / 100.00"
# No need to update marking guide as marking guide definition is already enabled by default
And I am on the "Assign 1" "assign activity" page logged in as teacher1
And I go to "Student 1" "Assign 1" activity advanced grading page
And I grade by filling the marking guide with:
| Grade Criteria 1 | 50 | Excellent work! |
| Grade Criteria 2 | 20 | Try harder |
And I press "Save changes"
When I am on the "Assign 1" "assign activity" page logged in as student1
# Student1 grade is now displayed.
Then I should see "70.00 / 100.00"
And I should see the marking guide information displayed as:
| criteria | description | remark | maxscore | criteriascore |
| Grade Criteria 1 | Grade 1 description for students | Excellent work! | 70 | 50 / 70 |
| Grade Criteria 2 | Grade 2 description for students | Try harder | 30 | 20 / 30 |
74 changes: 74 additions & 0 deletions mod/assign/tests/behat/behat_mod_assign.php
@@ -0,0 +1,74 @@
<?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 custom steps and configuration for mod_bigbluebuttonbn.
*
* @package mod_assign
* @category test
* @copyright 2024 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use Behat\Gherkin\Node\TableNode;

/**
* Behat custom steps and configuration for mod_assign.
*
* @package mod_assign
* @category test
* @copyright 2024 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_assign extends behat_base {

/**
* Check that the marking guide information is displayed correctly.
*
* @Then /^I should see the marking guide information displayed as:$/
* @param TableNode $table The table of marking guide information to check.
*/
public function i_should_see_marking_guide_information(TableNode $table) {

if (!$table->getRowsHash()) {
return;
}

$criteriacheck = 1;
foreach ($table as $row) {

$locator = "//table[@id='guide0-criteria']/tbody/tr[$criteriacheck]/td";

$this->assertSession()->elementContains('xpath', "{$locator}[@class='descriptionreadonly']", $row['criteria']);
$this->assertSession()->elementContains('xpath', "{$locator}[@class='descriptionreadonly']", $row['description']);

if (!empty($row['remark'])) {
$this->assertSession()->elementContains('xpath', "{$locator}[@class='remark']", $row['remark']);
}

if (!empty($row['maxscore'])) {
$this->assertSession()->elementContains('xpath', "{$locator}[@class='descriptionreadonly']", $row['maxscore']);
}

if (!empty($row['criteriascore'])) {
$this->assertSession()->elementContains('xpath', "{$locator}[@class='score']", $row['criteriascore']);
}

$criteriacheck++;
}
}
}

0 comments on commit 503cd95

Please sign in to comment.