From 78cd07f761ba865baee2d190c1e2dad6bf20848c Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 10 Aug 2015 13:27:45 +0100 Subject: [PATCH] MDL-51014 behat: Wait for filepicker to load repository --- lib/behat/behat_files.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/behat/behat_files.php b/lib/behat/behat_files.php index 34afbdbc4d2..8ad9f236290 100644 --- a/lib/behat/behat_files.php +++ b/lib/behat/behat_files.php @@ -193,6 +193,14 @@ class behat_files extends behat_base { $this->ensure_node_is_visible($add); $add->click(); + // Wait for the default repository (if any) to load. This checks that + // the relevant div exists and that it does not include the loading image. + $this->ensure_element_exists( + "//div[contains(concat(' ', normalize-space(@class), ' '), ' file-picker ')]" . + "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" . + "[not(descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content-loading ')])]", + 'xpath_element'); + // Getting the repository link and opening it. $repoexception = new ExpectationException('The "' . $repositoryname . '" repository has not been found', $this->getSession()); @@ -210,7 +218,11 @@ class behat_files extends behat_base { // Selecting the repo. $this->ensure_node_is_visible($repositorylink); - $repositorylink->click(); + if (!$repositorylink->getParent()->getParent()->hasClass('active')) { + // If the repository link is active, then the repository is already loaded. + // Clicking it while it's active causes issues, so only click it when it isn't (see MDL-51014). + $repositorylink->click(); + } } /**