diff --git a/src/support/steps/lcp-beacon-script.ts b/src/support/steps/lcp-beacon-script.ts index 22eee6b..7c690a0 100644 --- a/src/support/steps/lcp-beacon-script.ts +++ b/src/support/steps/lcp-beacon-script.ts @@ -52,8 +52,11 @@ Given('I visit the following urls in {string}', async function (this: ICustomWor for (const row of data) { const url: string = `${WP_BASE_URL}/${row[0]}`; await this.utils.visitPage(row[0]); - // Wait for 2 seconds before fetching from DB. - await this.page.waitForTimeout(2000); + // Wait the beacon to add an attribute `beacon-complete` to true before fetching from DB. + await this.page.waitForFunction(() => { + const beacon = document.querySelector('[data-name="wpr-lcp-beacon"]'); + return beacon && beacon.getAttribute('beacon-completed') === 'true'; + }); // Get the LCP/ATF from the DB sql = `SELECT lcp, viewport FROM ${tablePrefix}wpr_above_the_fold WHERE url LIKE "%${row[0]}%"`;