diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 8a71e9a8f..265d7e3de 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -509,16 +509,16 @@ export class TestingBehatRuntimeService { getHeader(): string { this.log('Action - Get header'); - let titles = Array.from(document.querySelectorAll('.ion-page:not(.ion-page-hidden) > ion-header h1')) + const getBySelector = (selector: string ) => Array.from(document.querySelectorAll(selector)) .filter((title) => TestingBehatDomUtils.isElementVisible(title, document.body)) - .map((title) => title.innerText.trim()); + .map((title) => title.innerText.trim()) + .filter((title) => title.length > 0); + + let titles = getBySelector('.ion-page:not(.ion-page-hidden) > ion-header h1'); // Collapsed title, get the floating title. - if (titles.length < 0 || (titles.length === 1 && titles[0] === '')) { - titles = Array.from(document.querySelectorAll( - '.ion-page:not(.ion-page-hidden) h1.collapsible-header-floating-title', - )).filter((title) => TestingBehatDomUtils.isElementVisible(title, document.body)) - .map((title) => title.innerText.trim()); + if (titles.length === 0) { + titles = getBySelector('.ion-page:not(.ion-page-hidden) h1.collapsible-header-floating-title'); } if (titles.length > 1) {