MOBILE-3833 behat: Fix pressElement helper
Behat runtime helpers cannot use async/await because asynchronous errors won't be returned to the php runtimemain
parent
5b66ef7f69
commit
7359114bf6
|
@ -511,24 +511,41 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Press an element.
|
* Make sure that an element is visible and wait to trigger the callback.
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} element Element to press.
|
* @param {HTMLElement} element Element.
|
||||||
|
* @param {Function} callback Callback called when the element is visible, passing bounding box parameter.
|
||||||
*/
|
*/
|
||||||
const pressElement = async function(element) {
|
const ensureElementVisible = function(element, callback) {
|
||||||
// Scroll the item into view.
|
|
||||||
const initialRect = element.getBoundingClientRect();
|
const initialRect = element.getBoundingClientRect();
|
||||||
|
|
||||||
element.scrollIntoView(false);
|
element.scrollIntoView(false);
|
||||||
|
|
||||||
await new Promise(resolve => requestAnimationFrame(resolve));
|
requestAnimationFrame(function () {
|
||||||
|
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
|
|
||||||
if (initialRect.y !== rect.y) {
|
if (initialRect.y !== rect.y) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
setTimeout(function () {
|
||||||
|
callback(rect);
|
||||||
|
}, 300);
|
||||||
|
addPendingDelay();
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback(rect);
|
||||||
|
});
|
||||||
|
|
||||||
|
addPendingDelay();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Press an element.
|
||||||
|
*
|
||||||
|
* @param {HTMLElement} element Element to press.
|
||||||
|
*/
|
||||||
|
const pressElement = function(element) {
|
||||||
|
ensureElementVisible(element, function(rect) {
|
||||||
// Simulate a mouse click on the button.
|
// Simulate a mouse click on the button.
|
||||||
const eventOptions = {
|
const eventOptions = {
|
||||||
clientX: rect.left + rect.width / 2,
|
clientX: rect.left + rect.width / 2,
|
||||||
|
@ -558,6 +575,7 @@
|
||||||
|
|
||||||
// Mark busy until the button click finishes processing.
|
// Mark busy until the button click finishes processing.
|
||||||
addPendingDelay();
|
addPendingDelay();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue