Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created April 18, 2023 00:45
Show Gist options
  • Save ChrisLTD/9665a73b67cf77d05abde36dfa4d23e0 to your computer and use it in GitHub Desktop.
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
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