MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / assertScreenshot

Function assertScreenshot

front_end/testing/DOMHelpers.ts:328–353  ·  view source on GitHub ↗
(filename: string)

Source from the content-addressed store, hash-verified

326 * The function relies on the bindings exposed via the karma config.
327 */
328export async function assertScreenshot(filename: string) {
329 // To avoid a lot of empty space in the screenshot.
330 document.getElementById(TEST_CONTAINER_ID)!.style.width = 'fit-content';
331 let frame: Window|null = window;
332 while (frame) {
333 frame.scrollTo(0, 0);
334 frame = frame.parent !== frame ? frame.parent : null;
335 }
336
337 // For test we load the fonts though the network - front_end/testing/test_setup.ts
338 // Which means we may try to take screenshot while they are loading
339 await document.fonts.ready;
340 await raf();
341 // Pending activity before taking screenshots results in flakiness.
342 await checkForPendingActivity();
343 if (!window.assertScreenshot) {
344 window.assertScreenshot = async () => {
345 debugger; // eslint-disable-line no-debugger
346 return undefined;
347 };
348 }
349 const errorMessage = await window.assertScreenshot(`#${TEST_CONTAINER_ID}`, filename);
350 if (errorMessage) {
351 throw new Error(errorMessage);
352 }
353}
354
355export function setColorScheme(scheme: 'dark'|'light'): void {
356 document.documentElement.classList.toggle('theme-with-dark-background', scheme === 'dark');

Calls 3

rafFunction · 0.85
checkForPendingActivityFunction · 0.85
assertScreenshotMethod · 0.80

Tested by 3

runEventDetailsTestFunction · 0.40
rendersInsightFunction · 0.40