diff --git a/mod/messages/tests/behat/settings.feature b/mod/messages/tests/behat/settings.feature new file mode 100644 index 000000000..227ddfc1a --- /dev/null +++ b/mod/messages/tests/behat/settings.feature @@ -0,0 +1,18 @@ +@mod @mod_messages @app @javascript +Feature: Test messages settings + + Background: + Given the following "users" exist: + | username | + | student1 | + + Scenario: Modify settings + When I enter the app + And I log in as "student1" + And I press "Messages" in the app + And I press "Message preferences" in the app + And I select "My contacts only" in the app + Then "My contacts only" should be selected in the app + + And I select "My contacts and anyone in my courses" in the app + Then "My contacts and anyone in my courses" should be selected in the app diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js index e5c99e3f9..a3e542f80 100644 --- a/tests/behat/app_behat_runtime.js +++ b/tests/behat/app_behat_runtime.js @@ -205,7 +205,8 @@ const ariaCurrent = element.getAttribute('aria-current'); if ( (ariaCurrent && ariaCurrent !== 'false') || - (element.getAttribute('aria-selected') === 'true') + (element.getAttribute('aria-selected') === 'true') || + (element.getAttribute('aria-checked') === 'true') ) return true; diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index 405ac532c..c2b753d0a 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -423,7 +423,7 @@ class behat_app extends behat_base { // Note there are two 'Log in' texts visible (the title and the button) so we have to use // a 'near' value here. - $this->i_press_near_in_the_app('Log in', 'Forgotten'); + $this->i_press_in_the_app('Log in', 'Forgotten'); // Wait until the main page appears. $this->spin( @@ -510,27 +510,29 @@ class behat_app extends behat_base { * Note it is difficult to use the standard 'click on' or 'press' steps because those do not * distinguish visible items and the app always has many non-visible items in the DOM. * - * @Given /^I press "(?P(?:[^"]|\\")*)" in the app$/ - * @param string $text Text identifying click target - * @throws DriverException If the press doesn't work - */ - public function i_press_in_the_app(string $text) { - $this->press($text); - } - - /** - * Clicks on / touches something that is visible in the app, near some other text. - * - * This is the same as the other step, but when there are multiple matches, it picks the one - * nearest (in DOM terms) the second text. The second text should be an exact match, or a partial - * match that only has one result. - * - * @Given /^I press "(?P(?:[^"]|\\")*)" near "(?P(?:[^"]|\\")*)" in the app$/ + * @Then /^I press "(?P(?:[^"]|\\")*)"(?: near "(?P(?:[^"]|\\")*)")? in the app$/ * @param string $text Text identifying click target * @param string $near Text identifying a nearby unique piece of text * @throws DriverException If the press doesn't work */ - public function i_press_near_in_the_app(string $text, string $near) { + public function i_press_in_the_app($text, $near='') { + $this->press($text, $near); + } + + /** + * Select an item from a list of options, such as a radio button. + * + * It may be necessary to use this step instead of "I press..." because radio buttons in Ionic are initialized + * with JavaScript, and clicks may not work until they are initialized properly which may cause flaky tests due + * to race conditions. + * + * @Then /^I select "(?P(?:[^"]|\\")*)"(?: near "(?P(?:[^"]|\\")*)")? in the app$/ + * @param string $text Text identifying click target + * @param string $near Text identifying a nearby unique piece of text + * @throws DriverException If the press doesn't work + */ + public function i_select_in_the_app($text, $near='') { + $this->getSession()->wait(100); $this->press($text, $near); }