The following assertion exceeds the 30000ms threshold. Does it look like I am structuring the assertion correctly?
test.beforeEach(async ({ page }) => {
await page.goto('https://my-site.com/my-page')
})
test('comscore', async ({ page }) => {
const responsePromise = page.waitForResponse(/https:\/\/sb\.scorecardresearch\.com\/b.*/)
const response = await responsePromise
expect(response.ok()).toBe(true)
})
This thread is trying to answer question "How can I structure Playwright tests to assert that multiple third-party scripts load correctly without causing too much network strain or having the test timeout if one script fails to load?"
technically not but don't you miss a click or some other action which would trigger this route /https://sb.scorecardresearch.com/b.*/?
That works well. But, I want to test a handful of third parties loading. If I put all the responsePromises in the same test, if the first one times out, none of the other responsePromises resolve. I want to use the same goto for triggering all the responsePromises though. I do not want to put an undue amount of network strain on the app running so many gotos in succession, which is what would happen if each third party was in its own test with its own goto. Here is my test following my most recent refactor.
import { test, expect } from '@playwright/test'
test('homepage third parties', async ({ page }) => {
const responsePromises = {
comscore: page.waitForResponse(/https:\/\/sb\.scorecardresearch\.com\/b.*/), // If this promise never resolves, the whole test times out.
ga4: page.waitForResponse(/https:\/\/analytics\.google\.com\/g\/collect.*/),
chartbeat: page.waitForResponse(/https:\/\/ping\.chartbeat\.net\/ping.*/),
gam: page.waitForResponse(/https:\/\/securepubads\.g\.doubleclick\.net\/gampad\/ads.*/),
permutive: page.waitForResponse(/https:\/\/api\.permutive\.com\/v2\.0\/batch\/events.*/)
}
await page.goto('https://my-site.com')
for (const [key, responsePromise] of Object.entries(responsePromises)) {
console.log(`homepage: ${key}`)
const response = await responsePromise
expect(response.ok() || response.status() === 302).toBe(true)
}
})
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].