Skip to content

Commit

Permalink
MDL-42625 behat: Wrapping select an option extra actions in a try & c…
Browse files Browse the repository at this point in the history
…atch

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.
  • Loading branch information
David Monllao authored and stronk7 committed Dec 12, 2013
1 parent bdd5a6c commit fff500c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lib/behat/form_field/behat_form_select.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,42 @@ public function set_value($value) {
// with elements inside containers.
$optionnodes = $this->session->getDriver()->find($optionxpath);
if ($optionnodes) {
current($optionnodes)->click();
// Wrapped in a try & catch as we can fall into race conditions
// and the element may not be there.
try {
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 {
// Multiple ones needs the click in the select.
$this->field->click();
// 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.
$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.
if (!$this->session->getDriver()->find($optionxpath)) {
return;
}

// Repeating the select as some drivers (chrome that I know) are moving
// to another option after the general select field click above.
$this->field->selectOption($value);
// 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
// to another option after the general select field click above.
$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;
}
}
}

Expand Down

0 comments on commit fff500c

Please sign in to comment.