From 1815059e285848116cba2205282089dbf868cbb5 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Fri, 30 Aug 2024 11:26:28 +0200 Subject: [PATCH] MOBILE-4616 behat: Block Behat for at least 500ms after a press --- src/testing/services/behat-blocking.ts | 12 ++++++++++++ src/testing/services/behat-runtime.ts | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/testing/services/behat-blocking.ts b/src/testing/services/behat-blocking.ts index b58407b0d..b56159ea4 100644 --- a/src/testing/services/behat-blocking.ts +++ b/src/testing/services/behat-blocking.ts @@ -139,6 +139,18 @@ export class TestingBehatBlockingService { this.unblock(key); } + /** + * Adds a pending key to the array, and remove it after some time. + * + * @param milliseconds Number of milliseconds to wait before the key is removed. + * @returns Promise resolved after the time has passed. + */ + async wait(milliseconds: number): Promise { + const key = this.block(); + await CoreWait.wait(milliseconds); + this.unblock(key); + } + /** * It would be really beautiful if you could detect CSS transitions and animations, that would * cover almost everything, but sadly there is no way to do this because the transitionstart diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index c030715a6..d3c612236 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -219,6 +219,9 @@ export class TestingBehatRuntimeService { // Click button await TestingBehatDomUtils.pressElement(foundButton); + // Block Behat for at least 500ms, WS calls or DOM changes might not begin immediately. + TestingBehatBlocking.wait(500); + return 'OK'; } @@ -446,6 +449,9 @@ export class TestingBehatRuntimeService { await TestingBehatDomUtils.pressElement(found); + // Block Behat for at least 500ms, WS calls or DOM changes might not begin immediately. + TestingBehatBlocking.wait(500); + return 'OK'; } catch (error) { return 'ERROR: ' + error.message;