From aa9b943e057ddcbcf1d39fbcdd9f9db389fc7807 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 1 Dec 2021 17:33:15 +0100 Subject: [PATCH] MOBILE-3926 behat: Improve enter course step --- tests/behat/behat_app.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index c7f8b193d..051e8560b 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -585,14 +585,19 @@ class behat_app extends behat_base { /** * User enters a course in the app. * - * @Given /^I enter the course "(.+)" in the app$/ + * @Given /^I enter the course "(.+?)"(?: as "(.+)")? in the app$/ * @param string $coursename Course name * @throws DriverException If the button push doesn't work */ - public function i_enter_the_course_in_the_app(string $coursename) { - try { - $this->i_press_in_the_app('"My courses" near "Messages"'); - } catch (DriverException $e) { + public function i_enter_the_course_in_the_app(string $coursename, ?string $username = null) { + if (!is_null($username)) { + $this->i_enter_the_app(); + $this->login($username); + } + + $mycoursesfound = $this->evaluate_script("return window.behat.find({ text: 'My courses', near: { text: 'Messages' } });"); + + if ($mycoursesfound !== 'OK') { // My courses not present enter from Dashboard. $this->i_press_in_the_app('"Home" near "Messages"'); $this->i_press_in_the_app('"Dashboard"'); @@ -600,14 +605,13 @@ class behat_app extends behat_base { $this->wait_for_pending_js(); - return true; + return; } + $this->i_press_in_the_app('"My courses" near "Messages"'); $this->i_press_in_the_app('"'.$coursename.'"'); $this->wait_for_pending_js(); - - return true; } /**