Created
April 18, 2023 00:45
-
-
Save ChrisLTD/9665a73b67cf77d05abde36dfa4d23e0 to your computer and use it in GitHub Desktop.
Helper you can use to wait for specific graphql queries to finish in Playwright
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Page } from '@playwright/test'; | |
export async function waitForGraphQL( | |
page: Page, | |
operationName: string | |
): Promise<void> { | |
await page.waitForResponse(async (response) => { | |
if (response.url().endsWith('/graphql')) { | |
const responseText = await response.text(); | |
const responseData = JSON.parse(responseText); | |
return responseData.data && responseData.data[operationName]; | |
} | |
return false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment