From fe2c4474a9acf600de76845f635753c3aa6b6f04 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 10 Mar 2022 15:14:44 +0100 Subject: [PATCH] MOBILE-3833 behat: Wait for scroll before click --- tests/behat/app_behat_runtime.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js index 7d04487c1..baab56f95 100644 --- a/tests/behat/app_behat_runtime.js +++ b/tests/behat/app_behat_runtime.js @@ -515,12 +515,20 @@ * * @param {HTMLElement} element Element to press. */ - const pressElement = function(element) { + const pressElement = async function(element) { // Scroll the item into view. + const initialRect = element.getBoundingClientRect(); + element.scrollIntoView(false); + await new Promise(resolve => requestAnimationFrame(resolve)); + const rect = element.getBoundingClientRect(); + if (initialRect.y !== rect.y) { + await new Promise(resolve => setTimeout(resolve, 300)); + } + // Simulate a mouse click on the button. const eventOptions = { clientX: rect.left + rect.width / 2,