diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js index 54daed900..4d0c9a940 100644 --- a/tests/behat/app_behat_runtime.js +++ b/tests/behat/app_behat_runtime.js @@ -349,10 +349,16 @@ * Function to find elements based on their text or Aria label. * * @param {object} locator Element locator. + * @param {boolean} insideSplitView Whether to search only inside the split view contents. * @return {HTMLElement} Found elements */ - const findElementsBasedOnText = function(locator) { - const topContainer = document.querySelector('ion-alert, ion-popover, ion-action-sheet, core-ion-tab.show-tab ion-page.show-page, ion-page.show-page, html'); + const findElementsBasedOnText = function(locator, insideSplitView) { + let topContainer = document.querySelector('ion-alert, ion-popover, ion-action-sheet, core-ion-tab.show-tab ion-page.show-page, ion-page.show-page, html'); + + if (insideSplitView) { + topContainer = topContainer.querySelector('core-split-view ion-router-outlet'); + } + let container = topContainer; if (topContainer && locator.near) { @@ -382,7 +388,7 @@ if (filteredElements.length > 0) { return filteredElements; } - } while ((container = getParentElement(container)) && container !== topContainer); + } while (container !== topContainer && (container = getParentElement(container)) && container !== topContainer); return []; }; @@ -497,21 +503,23 @@ }; /** - * Function to find an arbitrary item based on its text or aria label. + * Function to find an arbitrary element based on its text or aria label. * * @param {object} locator Element locator. + * @param {boolean} insideSplitView Whether to search only inside the split view contents. * @return {string} OK if successful, or ERROR: followed by message */ - const behatFind = function(locator) { - log('Action - Find', locator); + const behatFind = function(locator, insideSplitView) { + log('Action - Find', { locator, insideSplitView }); try { - const element = findElementsBasedOnText(locator)[0]; + const element = findElementsBasedOnText(locator, insideSplitView)[0]; if (!element) { return 'ERROR: No matches for text'; } + log('Action - Found', { locator, insideSplitView, element }); return 'OK'; } catch (error) { return 'ERROR: ' + error.message; @@ -573,7 +581,6 @@ titles = titles.filter(function(title) { return isElementVisible(title, document.body); }); - if (titles.length > 1) { return 'ERROR: Too many possible titles'; @@ -597,7 +604,6 @@ const behatSetField = function(field, value) { log('Action - Set field ' + field + ' to: ' + value); - const found = findElementsBasedOnText({ text: field, selector: 'input, textarea, [contenteditable="true"]' })[0]; if (!found) { return 'ERROR: No matches for text'; @@ -656,6 +662,8 @@ * @return {object} Component instance */ const behatGetComponentInstance = function(selector, className) { + log('Action - Get component instance ' + selector + ', ' + className); + const activeElement = Array.from(document.querySelectorAll(`.ion-page:not(.ion-page-hidden) ${selector}`)).pop(); if (!activeElement || !activeElement.__ngContext__) { diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index fb7fd3937..2386f1b2a 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -154,16 +154,18 @@ class behat_app extends behat_base { /** * Finds elements in the app. * - * @Then /^I should( not)? find (".+") in the app$/ + * @Then /^I should( not)? find (".+")( inside the split-view content)? in the app$/ * @param bool $not * @param string $locator + * @param bool $insidesplitview */ - public function i_find_in_the_app(bool $not, string $locator) { + public function i_find_in_the_app(bool $not, string $locator, bool $insidesplitview = false) { $locator = $this->parse_element_locator($locator); $locatorjson = json_encode($locator); + $insidesplitviewjson = json_encode($insidesplitview); - $this->spin(function() use ($not, $locatorjson) { - $result = $this->evaluate_script("return window.behat.find($locatorjson);"); + $this->spin(function() use ($not, $locatorjson, $insidesplitviewjson) { + $result = $this->evaluate_script("return window.behat.find($locatorjson, $insidesplitviewjson);"); if ($not && $result === 'OK') { throw new DriverException('Error, found an item that should not be found');