MDL-42625 behat: Wrapping select an option extra actions in a try & catch

To select an option is specially painful, every browser
behaves differently and phantomjs just joined the party
throwing "Element does not exist in cache" random
exceptions that we need to catch.
This commit is contained in:
David Monllao 2013-12-12 16:38:25 +08:00 committed by Eloy Lafuente (stronk7)
parent bdd5a6c5c2
commit fff500c727

View file

@ -101,21 +101,42 @@ class behat_form_select extends behat_form_field {
// with elements inside containers. // with elements inside containers.
$optionnodes = $this->session->getDriver()->find($optionxpath); $optionnodes = $this->session->getDriver()->find($optionxpath);
if ($optionnodes) { if ($optionnodes) {
// Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there.
try {
current($optionnodes)->click(); current($optionnodes)->click();
} catch (Exception $e) {
// We continue and return as this means that the element is not there or it is not the same.
return;
}
} }
} else { } else {
// Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there.
try {
// Multiple ones needs the click in the select. // Multiple ones needs the click in the select.
$this->field->click(); $this->field->click();
} catch (Exception $e) {
// We continue and return as this means that the element is not there or it is not the same.
return;
}
// We ensure that the option is still there. // We ensure that the option is still there.
if (!$this->session->getDriver()->find($optionxpath)) { if (!$this->session->getDriver()->find($optionxpath)) {
return; return;
} }
// Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there.
try {
// Repeating the select as some drivers (chrome that I know) are moving // Repeating the select as some drivers (chrome that I know) are moving
// to another option after the general select field click above. // to another option after the general select field click above.
$this->field->selectOption($value); $this->field->selectOption($value);
} catch (Exception $e) {
// We continue and return as this means that the element is not there or it is not the same.
return;
}
} }
} }