import hideScrollBars from '../clientSideScripts/hideScrollbars' ; import setCustomCss from '../clientSideScripts/setCustomCss' ; import { CUSTOM_CSS_ID } from './constants' ; import { checkIsMobile , getAddressBarShadowPadding , getToolBarShadowPadding } from './utils' ; import getEnrichedInstanceData from '../methods/instanceData' ; import { BeforeScreenshotOptions , BeforeScreenshotResult } from './beforeScreenshot.interface' ; import { Executor } from '../methods/methods.interface' ; import hideRemoveElements from '../clientSideScripts/hideRemoveElements' ; import { yellow } from "chalk" ; import { LogLevel } from "./options.interface" ; /**
 * Methods that need to be executed before a screenshot will be taken
 */ export default async function beforeScreenshot ( executor , options , addShadowPadding = false ) { const { browserName , nativeWebScreenshot , platformName } = options . instanceData ; const { addressBarShadowPadding , disableCSSAnimation , hideElements , logLevel , noScrollBars , removeElements , toolBarShadowPadding , } = options ; const addressBarPadding = getAddressBarShadowPadding ( { platformName , browserName , nativeWebScreenshot , addressBarShadowPadding , addShadowPadding , } ) ; const toolBarPadding = getToolBarShadowPadding ( { platformName , browserName , toolBarShadowPadding , addShadowPadding } ) ; if ( noScrollBars ) { await executor ( hideScrollBars , noScrollBars ) ; } if ( hideElements . length > 0 || removeElements . length > 0 ) { try { await executor ( hideRemoveElements , { hide : hideElements , remove : removeElements } , true ) ; } catch ( e ) { if ( logLevel === LogLevel . debug || logLevel === LogLevel . warn ) { console . log ( yellow ( `
#####################################################################################
 WARNING:
 (One of) the elements that needed to be hidden or removed could not be found on the
 page and caused this error
 Error: ${ e }
 We made sure the test didn't break.
#####################################################################################
` ) ) ; } } } if ( disableCSSAnimation || checkIsMobile ( platformName ) ) { await executor ( setCustomCss , { addressBarPadding , disableCSSAnimation , id : CUSTOM_CSS_ID , toolBarPadding } ) ; } const instanceOptions = { addressBarShadowPadding : options . addressBarShadowPadding , toolBarShadowPadding : options . toolBarShadowPadding , ... ( options . instanceData ) , } ; return getEnrichedInstanceData ( executor , instanceOptions , addShadowPadding ) ; }