@@ -41,8 +41,8 @@ async function takePageScreenshot(
4141 screenshotOptions ?: { maxDiffPixelRatio ?: number } ,
4242) : Promise < void > {
4343 const viewport = page . viewportSize ( ) ?? { width : 1200 , height : 800 } ;
44- const hasPadding = await page . evaluate ( ( ) => ! ! document . documentElement . style . paddingRight ) ;
45- const width = hasPadding ? viewport . width - 15 : viewport . width ;
44+ const htmlOffsetWidth = await page . evaluate ( ( ) => document . documentElement . offsetWidth ) ;
45+ const width = Math . min ( htmlOffsetWidth , viewport . width ) ;
4646 const clip = { x : 0 , y : 0 , width, height : viewport . height } ;
4747 await expect ( page ) . toHaveScreenshot ( [ name ] , { maxDiffPixelRatio : 0.20 , clip, ...screenshotOptions } ) ;
4848}
@@ -56,21 +56,15 @@ async function takeElementScreenshot(
5656 const locator = typeof element === 'string' ? page . locator ( element ) : element ;
5757 const selector = typeof element === 'string' ? element : null ;
5858
59- const overflowClip = selector
59+ const clip = selector
6060 ? await getVisualClip ( page , selector )
6161 : await getLocatorScrollClip ( locator ) ;
6262
63- const clip = overflowClip ?? await locator . evaluate ( ( el ) => {
64- const r = el . getBoundingClientRect ( ) ;
65- return {
66- x : Math . round ( r . x ) ,
67- y : Math . round ( r . y ) ,
68- width : Math . round ( r . width ) ,
69- height : Math . floor ( r . height ) ,
70- } ;
71- } ) ;
72-
73- await expect ( page ) . toHaveScreenshot ( [ name ] , { maxDiffPixelRatio : 0.15 , clip, ...screenshotOptions } ) ;
63+ if ( clip ) {
64+ await expect ( page ) . toHaveScreenshot ( [ name ] , { maxDiffPixelRatio : 0.15 , clip, ...screenshotOptions } ) ;
65+ } else {
66+ await expect ( locator ) . toHaveScreenshot ( [ name ] , { maxDiffPixelRatio : 0.15 , ...screenshotOptions } ) ;
67+ }
7468}
7569
7670async function simulateTestCafeScrollbar ( page : Page ) : Promise < boolean > {
0 commit comments