MOBILE-3926 behat: Add split-view scoping to find
parent
e9266ad9fd
commit
9724088a87
|
@ -349,10 +349,16 @@
|
||||||
* Function to find elements based on their text or Aria label.
|
* Function to find elements based on their text or Aria label.
|
||||||
*
|
*
|
||||||
* @param {object} locator Element locator.
|
* @param {object} locator Element locator.
|
||||||
|
* @param {boolean} insideSplitView Whether to search only inside the split view contents.
|
||||||
* @return {HTMLElement} Found elements
|
* @return {HTMLElement} Found elements
|
||||||
*/
|
*/
|
||||||
const findElementsBasedOnText = function(locator) {
|
const findElementsBasedOnText = function(locator, insideSplitView) {
|
||||||
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');
|
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;
|
let container = topContainer;
|
||||||
|
|
||||||
if (topContainer && locator.near) {
|
if (topContainer && locator.near) {
|
||||||
|
@ -382,7 +388,7 @@
|
||||||
if (filteredElements.length > 0) {
|
if (filteredElements.length > 0) {
|
||||||
return filteredElements;
|
return filteredElements;
|
||||||
}
|
}
|
||||||
} while ((container = getParentElement(container)) && container !== topContainer);
|
} while (container !== topContainer && (container = getParentElement(container)) && container !== topContainer);
|
||||||
|
|
||||||
return [];
|
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 {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
|
* @return {string} OK if successful, or ERROR: followed by message
|
||||||
*/
|
*/
|
||||||
const behatFind = function(locator) {
|
const behatFind = function(locator, insideSplitView) {
|
||||||
log('Action - Find', locator);
|
log('Action - Find', { locator, insideSplitView });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const element = findElementsBasedOnText(locator)[0];
|
const element = findElementsBasedOnText(locator, insideSplitView)[0];
|
||||||
|
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return 'ERROR: No matches for text';
|
return 'ERROR: No matches for text';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log('Action - Found', { locator, insideSplitView, element });
|
||||||
return 'OK';
|
return 'OK';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return 'ERROR: ' + error.message;
|
return 'ERROR: ' + error.message;
|
||||||
|
@ -574,7 +582,6 @@
|
||||||
return isElementVisible(title, document.body);
|
return isElementVisible(title, document.body);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (titles.length > 1) {
|
if (titles.length > 1) {
|
||||||
return 'ERROR: Too many possible titles';
|
return 'ERROR: Too many possible titles';
|
||||||
} else if (!titles.length) {
|
} else if (!titles.length) {
|
||||||
|
@ -597,7 +604,6 @@
|
||||||
const behatSetField = function(field, value) {
|
const behatSetField = function(field, value) {
|
||||||
log('Action - Set field ' + field + ' to: ' + value);
|
log('Action - Set field ' + field + ' to: ' + value);
|
||||||
|
|
||||||
|
|
||||||
const found = findElementsBasedOnText({ text: field, selector: 'input, textarea, [contenteditable="true"]' })[0];
|
const found = findElementsBasedOnText({ text: field, selector: 'input, textarea, [contenteditable="true"]' })[0];
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return 'ERROR: No matches for text';
|
return 'ERROR: No matches for text';
|
||||||
|
@ -656,6 +662,8 @@
|
||||||
* @return {object} Component instance
|
* @return {object} Component instance
|
||||||
*/
|
*/
|
||||||
const behatGetComponentInstance = function(selector, className) {
|
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();
|
const activeElement = Array.from(document.querySelectorAll(`.ion-page:not(.ion-page-hidden) ${selector}`)).pop();
|
||||||
|
|
||||||
if (!activeElement || !activeElement.__ngContext__) {
|
if (!activeElement || !activeElement.__ngContext__) {
|
||||||
|
|
|
@ -154,16 +154,18 @@ class behat_app extends behat_base {
|
||||||
/**
|
/**
|
||||||
* Finds elements in the app.
|
* 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 bool $not
|
||||||
* @param string $locator
|
* @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);
|
$locator = $this->parse_element_locator($locator);
|
||||||
$locatorjson = json_encode($locator);
|
$locatorjson = json_encode($locator);
|
||||||
|
$insidesplitviewjson = json_encode($insidesplitview);
|
||||||
|
|
||||||
$this->spin(function() use ($not, $locatorjson) {
|
$this->spin(function() use ($not, $locatorjson, $insidesplitviewjson) {
|
||||||
$result = $this->evaluate_script("return window.behat.find($locatorjson);");
|
$result = $this->evaluate_script("return window.behat.find($locatorjson, $insidesplitviewjson);");
|
||||||
|
|
||||||
if ($not && $result === 'OK') {
|
if ($not && $result === 'OK') {
|
||||||
throw new DriverException('Error, found an item that should not be found');
|
throw new DriverException('Error, found an item that should not be found');
|
||||||
|
|
Loading…
Reference in New Issue