diff --git a/mod/forum/tests/behat/app_basic_usage.feature b/mod/forum/tests/behat/app_basic_usage.feature
index 6d59c7db0..015ac7f08 100755
--- a/mod/forum/tests/behat/app_basic_usage.feature
+++ b/mod/forum/tests/behat/app_basic_usage.feature
@@ -134,7 +134,7 @@ Feature: Test basic usage of forum activity in app
When I press "Reply" in the app
And I set the field "Message" to "not sent reply" in the app
And I press "Post to forum" in the app
- And I press "Display options" near "not sent reply" in the app
+ And I press "Display options" within "not sent reply" "ion-card" in the app
Then I should find "Edit" in the app
When I press "Edit" in the app
@@ -244,6 +244,8 @@ Feature: Test basic usage of forum activity in app
When I press "Reply" in the app
And I set the field "Message" to "test2" in the app
And I press "Post to forum" in the app
+ Then I should find "test2" "ion-card" in the app
+
When I enter the course "Course 1" as "teacher1" in the app
And I press "Test forum name" in the app
And I press "Auto-test" in the app
diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js
index baab56f95..f1bac741b 100644
--- a/tests/behat/app_behat_runtime.js
+++ b/tests/behat/app_behat_runtime.js
@@ -511,55 +511,73 @@
};
/**
- * Press an element.
+ * Make sure that an element is visible and wait to trigger the callback.
*
- * @param {HTMLElement} element Element to press.
+ * @param {HTMLElement} element Element.
+ * @param {Function} callback Callback called when the element is visible, passing bounding box parameter.
*/
- const pressElement = async function(element) {
- // Scroll the item into view.
+ const ensureElementVisible = function(element, callback) {
const initialRect = element.getBoundingClientRect();
element.scrollIntoView(false);
- await new Promise(resolve => requestAnimationFrame(resolve));
+ requestAnimationFrame(function () {
+ const rect = element.getBoundingClientRect();
- const rect = element.getBoundingClientRect();
+ if (initialRect.y !== rect.y) {
+ setTimeout(function () {
+ callback(rect);
+ }, 300);
+ addPendingDelay();
- if (initialRect.y !== rect.y) {
- await new Promise(resolve => setTimeout(resolve, 300));
- }
+ return;
+ }
- // Simulate a mouse click on the button.
- const eventOptions = {
- clientX: rect.left + rect.width / 2,
- clientY: rect.top + rect.height / 2,
- bubbles: true,
- view: window,
- cancelable: true,
- };
+ callback(rect);
+ });
- // Events don't bubble up across Shadow DOM boundaries, and some buttons
- // may not work without doing this.
- const parentElement = getParentElement(element);
-
- if (parentElement && parentElement.matches('ion-button, ion-back-button')) {
- element = parentElement;
- }
-
- // There are some buttons in the app that don't respond to click events, for example
- // buttons using the core-supress-events directive. That's why we need to send both
- // click and mouse events.
- element.dispatchEvent(new MouseEvent('mousedown', eventOptions));
-
- setTimeout(() => {
- element.dispatchEvent(new MouseEvent('mouseup', eventOptions));
- element.click();
- }, 300);
-
- // Mark busy until the button click finishes processing.
addPendingDelay();
};
+ /**
+ * Press an element.
+ *
+ * @param {HTMLElement} element Element to press.
+ */
+ const pressElement = function(element) {
+ ensureElementVisible(element, function(rect) {
+ // Simulate a mouse click on the button.
+ const eventOptions = {
+ clientX: rect.left + rect.width / 2,
+ clientY: rect.top + rect.height / 2,
+ bubbles: true,
+ view: window,
+ cancelable: true,
+ };
+
+ // Events don't bubble up across Shadow DOM boundaries, and some buttons
+ // may not work without doing this.
+ const parentElement = getParentElement(element);
+
+ if (parentElement && parentElement.matches('ion-button, ion-back-button')) {
+ element = parentElement;
+ }
+
+ // There are some buttons in the app that don't respond to click events, for example
+ // buttons using the core-supress-events directive. That's why we need to send both
+ // click and mouse events.
+ element.dispatchEvent(new MouseEvent('mousedown', eventOptions));
+
+ setTimeout(() => {
+ element.dispatchEvent(new MouseEvent('mouseup', eventOptions));
+ element.click();
+ }, 300);
+
+ // Mark busy until the button click finishes processing.
+ addPendingDelay();
+ });
+ };
+
/**
* Function to find and click an app standard button.
*
diff --git a/tests/behat/navigation_externallinks.feature b/tests/behat/navigation_externallinks.feature
index 4abf963fe..e79737ac5 100644
--- a/tests/behat/navigation_externallinks.feature
+++ b/tests/behat/navigation_externallinks.feature
@@ -16,17 +16,17 @@ Feature: It opens external links properly.
| forum | Test forum | Test forum | C1 | forum |
And the following forum discussions exist in course "Course 1":
| forum | user | name | message |
- | Test forum | student1 | Forum topic | See moodle.org |
+ | Test forum | student1 | Forum topic | See moodle.org external link |
Scenario: Click an external link
When I enter the course "Course 1" as "student1" in the app
And I press "Test forum" in the app
And I press "Forum topic" in the app
- And I press "moodle.org" in the app
+ And I press "moodle.org external link" in the app
Then I should find "You are about to leave the app" in the app
When I press "Cancel" in the app
- And I press "moodle.org" in the app
+ And I press "moodle.org external link" in the app
And I press "OK" in the app
Then the app should have opened a browser tab with url "moodle.org"
@@ -39,9 +39,9 @@ Feature: It opens external links properly.
When I close the browser tab opened by the app
When I close the popup in the app
And I press "Forum topic" in the app
- And I press "moodle.org" in the app
+ And I press "moodle.org external link" in the app
And I select "Don't show again." in the app
And I press "OK" in the app
And I close the browser tab opened by the app
- And I press "moodle.org" in the app
+ And I press "moodle.org external link" in the app
Then the app should have opened a browser tab with url "moodle.org"