Merge pull request #74 from NoelDeMartin/MOBILE-3833

MOBILE-3833 behat: Wait for scroll before click
main
Pau Ferrer Ocaña 2022-03-10 15:19:27 +01:00 committed by GitHub
commit 5b66ef7f69
1 changed files with 9 additions and 1 deletions

View File

@ -515,12 +515,20 @@
* *
* @param {HTMLElement} element Element to press. * @param {HTMLElement} element Element to press.
*/ */
const pressElement = function(element) { const pressElement = async function(element) {
// Scroll the item into view. // Scroll the item into view.
const initialRect = element.getBoundingClientRect();
element.scrollIntoView(false); element.scrollIntoView(false);
await new Promise(resolve => requestAnimationFrame(resolve));
const rect = element.getBoundingClientRect(); const rect = element.getBoundingClientRect();
if (initialRect.y !== rect.y) {
await new Promise(resolve => setTimeout(resolve, 300));
}
// 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,