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

This commit is contained in:
Andrew Hancox
2015-09-24 13:03:16 +08:00
committed by rajesh Taneja
parent 2dd2288807
commit e914864d08
+25
View File
@@ -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<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.
*