MDL-67813 core_filepicker: Handle ElementNotFoundException in behat step

Catches and handles ElementNotFoundException if thrown in the
i_should_see_elements_in_filepicker_repository() behat step in order to
enable the assertion that no elements exist in the repository content
area
This commit is contained in:
Mihail Geshoski
2020-05-28 12:06:31 +08:00
parent 1bb6231b32
commit f3fc0266ca
+7 -1
View File
@@ -28,6 +28,7 @@
require_once(__DIR__ . '/../../../lib/behat/core_behat_file_helper.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Gherkin\Node\TableNode as TableNode;
/**
@@ -342,7 +343,12 @@ class behat_filepicker extends behat_base {
"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" .
"//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]";
$elements = $this->find_all('xpath', $xpath);
try {
$elements = $this->find_all('xpath', $xpath);
} catch (ElementNotFoundException $e) {
$elements = [];
}
// Make sure the expected number is equal to the actual number of .fp-file elements.
if (count($elements) != $expectedcount) {
throw new ExpectationException("Found " . count($elements) .