mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Allow fields and buttons to be disabled in behat steps
This commit is contained in:
parent
2acd0889d4
commit
415a7d3c87
@ -519,17 +519,27 @@ JS;
|
||||
* Example: Then the field "Email" should be disabled
|
||||
* Example: Then the "Email" field should be disabled
|
||||
*
|
||||
* @Then /^the "(?P<field>(?:[^"]|\\")*)" field should be disabled/
|
||||
* @Then /^the field "(?P<field>(?:[^"]|\\")*)" should be disabled/
|
||||
* @Then /^the "(?P<name>(?:[^"]|\\")*)" (?P<type>(?:(field|button))) should (?P<negate>(?:(not |)))be disabled/
|
||||
* @Then /^the (?P<type>(?:(field|button))) "(?P<name>(?:[^"]|\\")*)" should (?P<negate>(?:(not |)))be disabled/
|
||||
*/
|
||||
public function stepFieldShouldBeDisabled($field) {
|
||||
public function stepFieldShouldBeDisabled($name, $type, $negate) {
|
||||
$page = $this->getSession()->getPage();
|
||||
$fieldElement = $page->findField($field);
|
||||
assertNotNull($fieldElement, sprintf("Field '%s' not found", $field));
|
||||
if($type == 'field') {
|
||||
$element = $page->findField($name);
|
||||
} else {
|
||||
$element = $page->find('named', array(
|
||||
'button', $this->getSession()->getSelectorsHandler()->xpathLiteral($name)
|
||||
));
|
||||
}
|
||||
|
||||
$disabledAttribute = $fieldElement->getAttribute('disabled');
|
||||
assertNotNull($element, sprintf("Element '%s' not found", $name));
|
||||
|
||||
assertNotNull($disabledAttribute, sprintf("Failed asserting field '%s' is disabled", $field));
|
||||
$disabledAttribute = $element->getAttribute('disabled');
|
||||
if(trim($negate)) {
|
||||
assertNull($disabledAttribute, sprintf("Failed asserting element '%s' is not disabled", $name));
|
||||
} else {
|
||||
assertNotNull($disabledAttribute, sprintf("Failed asserting element '%s' is disabled", $name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user