Behat: Avoid false positives in dropdown traversal

Was identifying fields like <input value="Select a page">
when querying for a drop down labelled "Page"
This commit is contained in:
Ingo Schommer 2013-09-14 18:29:04 +02:00
parent 8de227554e
commit e202d4b3b0

View File

@ -340,7 +340,7 @@ class CmsUiContext extends BehatContext
$field = $this->fixStepArgument($field); $field = $this->fixStepArgument($field);
$value = $this->fixStepArgument($value); $value = $this->fixStepArgument($value);
$nativeField = $this->getSession()->getPage()->findField($field); $nativeField = $this->getSession()->getPage()->find('named', array('select', $field));
if($nativeField) { if($nativeField) {
$nativeField->selectOption($value); $nativeField->selectOption($value);
return; return;
@ -351,7 +351,9 @@ class CmsUiContext extends BehatContext
// Find by label // Find by label
$formField = $this->getSession()->getPage()->findField($field); $formField = $this->getSession()->getPage()->findField($field);
if($formField) $formFields[] = $formField; if($formField && $formField->getTagName() == 'select') {
$formFields[] = $formField;
}
// Fall back to finding by title (for dropdowns without a label) // Fall back to finding by title (for dropdowns without a label)
if(!$formFields) { if(!$formFields) {
@ -369,6 +371,15 @@ class CmsUiContext extends BehatContext
$formFields = $this->getSession()->getPage()->findAll('xpath', "//*[@name='$field']"); $formFields = $this->getSession()->getPage()->findAll('xpath', "//*[@name='$field']");
} }
// Find by label
if(!$formFields) {
$label = $this->getSession()->getPage()->find('xpath', "//label[.='$field']");
if($label && $for = $label->getAttribute('for')) {
$formField = $this->getSession()->getPage()->find('xpath', "//*[@id='$for']");
if($formField) $formFields[] = $formField;
}
}
assertGreaterThan(0, count($formFields), sprintf( assertGreaterThan(0, count($formFields), sprintf(
'Chosen.js dropdown named "%s" not found', 'Chosen.js dropdown named "%s" not found',
$field $field