From e914864d08400ab1015afbafcf784c9ecd05745b Mon Sep 17 00:00:00 2001 From: Andrew Hancox Date: Tue, 28 Jul 2015 11:21:24 +0100 Subject: [PATCH] MDL-50940 behat: Added ability to check field value by xpath --- lib/tests/behat/behat_forms.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 932dec3a355..06c58b2bf0f 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -212,6 +212,31 @@ class behat_forms extends behat_base { } } + /** + * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. + * + * @Then /^the field with xpath "(?P(?:[^"]|\\")*)" matches value "(?P(?:[^"]|\\")*)"$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $fieldxpath + * @param string $value + * @return void + */ + public function the_field_with_xpath_matches_value($fieldxpath, $value) { + + // Get the field. + $fieldnode = $this->find('xpath', $fieldxpath); + $formfield = behat_field_manager::get_form_field($fieldnode, $this->getSession()); + + // Checks if the provided value matches the current field value. + if (!$formfield->matches($value)) { + $fieldvalue = $formfield->get_value(); + throw new ExpectationException( + 'The \'' . $fieldxpath . '\' value is \'' . $fieldvalue . '\', \'' . $value . '\' expected' , + $this->getSession() + ); + } + } + /** * Checks, the field does not match the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. *