mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
8de227554e
commit
e202d4b3b0
@ -340,7 +340,7 @@ class CmsUiContext extends BehatContext
|
||||
$field = $this->fixStepArgument($field);
|
||||
$value = $this->fixStepArgument($value);
|
||||
|
||||
$nativeField = $this->getSession()->getPage()->findField($field);
|
||||
$nativeField = $this->getSession()->getPage()->find('named', array('select', $field));
|
||||
if($nativeField) {
|
||||
$nativeField->selectOption($value);
|
||||
return;
|
||||
@ -351,7 +351,9 @@ class CmsUiContext extends BehatContext
|
||||
|
||||
// Find by label
|
||||
$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)
|
||||
if(!$formFields) {
|
||||
@ -369,6 +371,15 @@ class CmsUiContext extends BehatContext
|
||||
$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(
|
||||
'Chosen.js dropdown named "%s" not found',
|
||||
$field
|
||||
|
Loading…
Reference in New Issue
Block a user