MDL-50940 behat: Added ability to check field value by xpath

This commit is contained in:
Andrew Hancox
2015-07-28 11:21:24 +01:00
committed by rajesh Taneja
parent d230899db8
commit d9fddb0bc6

View File

@@ -240,6 +240,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<fieldxpath_string>(?:[^"]|\\")*)" matches value "(?P<field_value_string>(?:[^"]|\\")*)"$/
* @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.
*