From a90d4bda342afa344587233d010742050c3bca43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 10 Jan 2024 13:42:37 +0100 Subject: [PATCH] MOBILE-3947 behat: Fix tab select status check --- .../features/mainmenu/tests/behat/mainmenu.feature | 2 +- src/testing/services/behat-dom.ts | 12 ++++++++---- src/testing/services/behat-runtime.ts | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/features/mainmenu/tests/behat/mainmenu.feature b/src/core/features/mainmenu/tests/behat/mainmenu.feature index ae2e15c9d..684838483 100644 --- a/src/core/features/mainmenu/tests/behat/mainmenu.feature +++ b/src/core/features/mainmenu/tests/behat/mainmenu.feature @@ -32,7 +32,7 @@ Feature: Main Menu opens the right page And "Dashboard" "text" should appear before "Site home" "text" in the ".core-tabs-bar" "css_element" And "Home" "text" should appear before "My courses" "text" in the ".mainmenu-tabs" "css_element" - @ionic7_failure @lms_from4.0 + @lms_from4.0 Scenario: Opens My Courses when defaulthomepage is set to My Courses Given the following config values are set as admin: | defaulthomepage | 3 | diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index babfb4222..76c812564 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -76,11 +76,10 @@ export class TestingBehatDomUtilsService { * Check if an element is selected. * * @param element Element. - * @param container Container. * @param firstCall Whether this is the first call of the function. * @returns Whether the element is selected or not. */ - isElementSelected(element: HTMLElement, container: HTMLElement, firstCall = true): boolean { + isElementSelected(element: HTMLElement, firstCall = true): boolean { const ariaCurrent = element.getAttribute('aria-current'); const ariaSelected = element.getAttribute('aria-selected'); const ariaChecked = element.getAttribute('aria-checked'); @@ -96,14 +95,19 @@ export class TestingBehatDomUtilsService { if (inputElement) { return inputElement.value === 'on'; } + + const tabButtonElement = element.closest('ion-tab-button'); + if (tabButtonElement?.classList.contains('tab-selected')) { + return true; + } } const parentElement = this.getParentElement(element); - if (!parentElement || parentElement === container) { + if (!parentElement || parentElement.classList.contains('ion-page')) { return false; } - return this.isElementSelected(parentElement, container, false); + return this.isElementSelected(parentElement, false); } /** diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index fc32e4d50..9a6e7d5fc 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -326,7 +326,7 @@ export class TestingBehatRuntimeService { return 'ERROR: No element matches locator to find.'; } - return TestingBehatDomUtils.isElementSelected(element, document.body) ? 'YES' : 'NO'; + return TestingBehatDomUtils.isElementSelected(element) ? 'YES' : 'NO'; } catch (error) { return 'ERROR: ' + error.message; }