MOBILE-3926 behat: Implement scroll to step

main
Noel De Martin 2021-11-25 13:04:25 +01:00
parent 9724088a87
commit 89488bd71a
2 changed files with 51 additions and 0 deletions

View File

@ -526,6 +526,33 @@
}
};
/**
* Scroll an element into view.
*
* @param {object} locator Element locator.
* @return {string} OK if successful, or ERROR: followed by message
*/
const behatScrollTo = function(locator) {
log('Action - scrollTo', { locator });
try {
let element = findElementsBasedOnText(locator)[0];
if (!element) {
return 'ERROR: No matches for text';
}
element = element.closest('ion-item') ?? element.closest('button') ?? element;
element.scrollIntoView();
log('Action - Scrolled to', { locator, element });
return 'OK';
} catch (error) {
return 'ERROR: ' + error.message;
}
}
/**
* Check whether an item is selected or not.
*
@ -678,6 +705,7 @@
pressStandard : behatPressStandard,
closePopup : behatClosePopup,
find : behatFind,
scrollTo : behatScrollTo,
isSelected : behatIsSelected,
press : behatPress,
setField : behatSetField,

View File

@ -181,6 +181,29 @@ class behat_app extends behat_base {
$this->wait_for_pending_js();
}
/**
* Scroll to an element in the app.
*
* @When /^I scroll to (".+") in the app$/
* @param string $locator
*/
public function i_scroll_to_in_the_app(string $locator) {
$locator = $this->parse_element_locator($locator);
$locatorjson = json_encode($locator);
$this->spin(function() use ($locatorjson) {
$result = $this->evaluate_script("return window.behat.scrollTo($locatorjson);");
if ($result !== 'OK') {
throw new DriverException('Error finding item - ' . $result);
}
return true;
});
$this->wait_for_pending_js();
}
/**
* Trigger swipe gesture.
*