import hideScrollBars from '../clientSideScripts/hideScrollbars' ; import removeElementFromDom from '../clientSideScripts/removeElementFromDom' ; import { CUSTOM_CSS_ID } from './constants' ; import { checkIsMobile , formatFileName , getAndCreatePath } from './utils' ; import { saveBase64Image } from '../methods/images' ; import { join } from 'path' ; import { Executor } from '../methods/methods.interface' ; import { AfterScreenshotOptions , ScreenshotOutput } from './afterScreenshot.interfaces' ; import hideRemoveElements from '../clientSideScripts/hideRemoveElements' ; import { yellow } from "chalk" ; import { LogLevel } from "./options.interface" ; /**
 * Methods that need to be executed after a screenshot has been taken
 * to set all back to the original state
 */ export default async function afterScreenshot ( executor , options ) { const { actualFolder , base64Image , disableCSSAnimation , fileName : fileNameOptions , filePath , hideElements , hideScrollBars : noScrollBars , logLevel , platformName , removeElements , } = options ; const path = getAndCreatePath ( actualFolder , filePath ) ; const fileName = formatFileName ( fileNameOptions ) ; await saveBase64Image ( base64Image , join ( path , fileName ) ) ; if ( noScrollBars ) { await executor ( hideScrollBars , ! noScrollBars ) ; } if ( hideElements . length > 0 || removeElements . length > 0 ) { try { await executor ( hideRemoveElements , { hide : hideElements , remove : removeElements } , false ) ; } 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 ( removeElementFromDom , CUSTOM_CSS_ID ) ; } return { fileName , path , devicePixelRatio : fileNameOptions . devicePixelRatio , } ; }