Posts made by Joseph Rézeau

Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

In my regexp Behat tests I would like to check that the validation error messages work. I have this scenario:

Scenario: Create a Regexp question
    When I am on the "Course 1" "core_question > course question bank" page logged in as teacher
    And I add a "Regular expression short answer" question filling the form with:
      | Question name        | regularshortanswer-001                    |
      | Question text        | How much does this computer cost?         |
      | Default mark         | 1                                         |
      | Case sensitivity     | Yes, case must match                      |
      | id_answer_0          | 799.99$                                   |
      | id_fraction_0        | 100%                                      |
      | id_feedback_0        | OK.                                       |
      | id_answer_1          | approximately 800$                        |
      | id_fraction_1        | 90%                                       |
      | id_feedback_1        | Almost.                                   |
    Then I should see "In Answers with a grade > 0 these unescaped metacharacters are not allowed: . ^ $ * + { } \"
    And I set the field with xpath "//input[contains(@id, 'id_answer_1')]" to "approximately 800\$"
    And I click on "Save changes" "button"
    Then I should see "regularshortanswer-001"

Error message:  "regularshortanswer-001" text was not found in the page (Behat\Mink\Exception\ExpectationException)

The reason for this error is that the scenario never presses the Save changes button on the question edit form. Do I have to issue a special command after setting a field with xpath? Be more specific in the location of the Save changes button? Or should I simply give up on this validation test?

Average of ratings: -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Tim: "Your 'And the following "questions" exist:' won's work as it is. Did you copy that from your .feature file exactly? You need to change qtype to regexpshortanswer."
 
Of course, Tim. I actually had:
 
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | regexp| regexpshortanswer-001 for editing | frenchflag |
 
" Also, I assumey you have the file question/type/tests/helper.php, which defines the data for the frenchflag question?"
Yes, of course.
Average of ratings: Useful (2)
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

The windows resize workaround mentioned by @Renaat does work.

However, I was still curious to know why my regexp question type behat edit.feature test threw that 'Element not clickable' error, while the original shortanswer edit.feature test did not throw an error. I systematically compared my test with the original shortanswer test, and finally found out the culprit. 

In the shortanswer test we have:

And the following "questions" exist:
      | questioncategory | qtype       | name                        | template |
      | Test questions   | shortanswer | shortanswer-001 for editing | frogtoad |

In my regexp test I changed this to:

And the following "questions" exist:
      | questioncategory | qtype       | name                        | template |
      | Test questions   | shortanswer | regexpshortanswer-001 for editing | frenchflag |

The name I have given to my question is too long and causes the error. I shortened it to regexp-001 and the error is gone!

On the other hand if, in the shortanswere question test, I change shortanswer-001 to e.g. a-really-very-short-answer-001, the error message appears.

quod erat demonstrandum

Average of ratings: Useful (1)