From da98dd63067b5bf65524b2cab1c01c5bd17291f8 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 1 Aug 2023 18:03:29 +0900 Subject: [PATCH] MOBILE-4362 behat: Improve BBB wait steps --- .../tests/behat/behat_app.php | 64 +++++++++++++++---- .../tests/behat/basic_usage.feature | 17 ++--- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index cfb23569014..ca4f512aa9a 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -269,6 +269,26 @@ public function i_swipe_in_the_app(string $direction, bool $hasLocator = false, $this->getSession()->wait(300); } + /** + * Wait for a BBB room to start. + * + * @When I wait for the BigBlueButton room to start + */ + public function i_wait_bbb_room_to_start() { + $windowNames = $this->getSession()->getWindowNames(); + + $this->getSession()->switchToWindow(array_pop($windowNames)); + $this->spin(function($context) { + $joinmodal = $context->getSession()->getPage()->find('css', 'div[role="dialog"][aria-label="How would you like to join the audio?"]'); + + if ($joinmodal) { + return true; + } + + throw new DriverException('BBB room not started'); + }, false, 30); + } + /** * Check if elements are selected in the app. * @@ -646,24 +666,46 @@ public function i_press_in_the_app(string $locator) { /** * Performs a pull to refresh gesture. * - * @When I pull to refresh in the app + * @When /^I pull to refresh (?:until I find (".+") )?in the app$/ * @throws DriverException If the gesture is not available */ - public function i_pull_to_refresh_in_the_app() { - $this->spin(function() { - $result = $this->runtime_js('pullToRefresh()'); + public function i_pull_to_refresh_in_the_app(?string $locator = null) { + $timeout = 0; + $startTime = time(); - if ($result !== 'OK') { - throw new DriverException('Error pulling to refresh - ' . $result); + if (!is_null($locator)) { + $timeout = 60; + $locator = $this->parse_element_locator($locator); + } + + do { + $this->spin(function() { + $result = $this->runtime_js('pullToRefresh()'); + + if ($result !== 'OK') { + throw new DriverException('Error pulling to refresh - ' . $result); + } + + return true; + }); + + $this->wait_for_pending_js(); + + // Wait for UI to settle after refreshing. + $this->getSession()->wait(300); + + if (is_null($locator)) { + return; } - return true; - }); + $result = $this->runtime_js("find($locator)"); - $this->wait_for_pending_js(); + if ($result === 'OK') { + return; + } + } while ($timeout > (time() - $startTime)); - // Wait for UI to settle after refreshing. - $this->getSession()->wait(300); + throw new DriverException('Error finding element after PTR - ' . $result); } /** diff --git a/src/addons/mod/bigbluebuttonbn/tests/behat/basic_usage.feature b/src/addons/mod/bigbluebuttonbn/tests/behat/basic_usage.feature index 856d5e69894..abf8c890da8 100755 --- a/src/addons/mod/bigbluebuttonbn/tests/behat/basic_usage.feature +++ b/src/addons/mod/bigbluebuttonbn/tests/behat/basic_usage.feature @@ -49,9 +49,8 @@ Feature: Test basic usage of BBB activity in app And I should be able to press "Join session" in the app When I press "Join session" in the app - Then the app should have opened a browser tab with url "blindsidenetworks.com" - - Given I wait "10" seconds + And I wait for the BigBlueButton room to start + And I switch back to the app Then I should find "The session is in progress." in the app And I should find "1" near "Viewer" in the app And I should find "0" near "Moderator" in the app @@ -65,9 +64,8 @@ Feature: Test basic usage of BBB activity in app And I should be able to press "Join session" in the app When I press "Join session" in the app - Then the app should have opened a browser tab with url "blindsidenetworks.com" - - Given I wait "10" seconds + And I wait for the BigBlueButton room to start + And I switch back to the app Then I should find "The session is in progress." in the app And I should find "1" near "Moderator" in the app And I should find "0" near "Viewer" in the app @@ -86,12 +84,11 @@ Feature: Test basic usage of BBB activity in app And I switch to the browser tab opened by the app And I log in as "teacher1" And I click on "Join session" "link" - And I wait "10" seconds + And I wait for the BigBlueButton room to start And I switch back to the app And I press "Close" in the app - And I pull to refresh in the app - Then I should find "The session is in progress." in the app - And I should find "1" near "Moderator" in the app + And I pull to refresh until I find "The session is in progress" in the app + Then I should find "1" near "Moderator" in the app And I should find "0" near "Viewer" in the app And I should be able to press "Join session" in the app