diff --git a/packages/e2e-test-utils-playwright/src/request-utils/rest.ts b/packages/e2e-test-utils-playwright/src/request-utils/rest.ts index 667ccc1d9294d9..25f4729ff9eb15 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/rest.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/rest.ts @@ -3,6 +3,7 @@ */ import * as fs from 'fs/promises'; import { dirname } from 'path'; +import { expect } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; /** @@ -39,10 +40,29 @@ async function getAPIRootURL( request: APIRequestContext ) { } async function setupRest( this: RequestUtils ): Promise< StorageState > { - const [ nonce, rootURL ] = await Promise.all( [ - this.login(), - getAPIRootURL( this.request ), - ] ); + let nonce = ''; + let rootURL = ''; + + await expect + .poll( + async () => { + [ nonce, rootURL ] = await Promise.all( [ + this.login(), + getAPIRootURL( this.request ), + ] ); + + if ( ! nonce || ! rootURL ) { + return false; + } + + return true; + }, + { + message: 'Failed to setup REST API.', + timeout: 60_000, // 1 minute. + } + ) + .toBe( true ); const { cookies } = await this.request.storageState();