import { takeBase64Screenshot } from '../methods/screenshots' ; import { makeCroppedBase64Image } from '../methods/images' ; import beforeScreenshot from '../helpers/beforeScreenshot' ; import afterScreenshot from '../helpers/afterScreenshot' ; import { determineScreenRectangles } from '../methods/rectangles' ; import { Methods } from '../methods/methods.interface' ; import { Folders } from '../base.interface' ; import { SaveScreenOptions } from './screen.interfaces' ; import { BeforeScreenshotOptions , BeforeScreenshotResult } from '../helpers/beforeScreenshot.interface' ; import { InstanceData } from '../methods/instanceData.interfaces' ; import { AfterScreenshotOptions , ScreenshotOutput } from '../helpers/afterScreenshot.interfaces' ; import { RectanglesOutput , ScreenRectanglesOptions } from '../methods/rectangles.interfaces' ; /**
 * Saves an image of the viewport of the screen
 */ export default async function saveScreen ( methods , instanceData , folders , tag , saveScreenOptions ) { const { addressBarShadowPadding , formatImageName , logLevel , savePerInstance , toolBarShadowPadding } = saveScreenOptions . wic ; const disableCSSAnimation = 'disableCSSAnimation' in saveScreenOptions . method ? saveScreenOptions . method . disableCSSAnimation : saveScreenOptions . wic . disableCSSAnimation ; const hideScrollBars = 'hideScrollBars' in saveScreenOptions . method ? saveScreenOptions . method . hideScrollBars : saveScreenOptions . wic . hideScrollBars ; const hideElements = saveScreenOptions . method . hideElements || [ ] ; const removeElements = saveScreenOptions . method . removeElements || [ ] ; const beforeOptions = { instanceData , addressBarShadowPadding , disableCSSAnimation , hideElements , logLevel , noScrollBars : hideScrollBars , removeElements , toolBarShadowPadding , } ; const enrichedInstanceData = await beforeScreenshot ( methods . executor , beforeOptions ) ; const base64Image = await takeBase64Screenshot ( methods . screenShot ) ; const screenRectangleOptions = { devicePixelRatio : enrichedInstanceData . dimensions . window . devicePixelRatio , innerHeight : enrichedInstanceData . dimensions . window . innerHeight , innerWidth : enrichedInstanceData . dimensions . window . innerWidth , isAndroidChromeDriverScreenshot : enrichedInstanceData . isAndroidChromeDriverScreenshot , isAndroidNativeWebScreenshot : enrichedInstanceData . isAndroidNativeWebScreenshot , isIos : enrichedInstanceData . isIos , } ; const rectangles = determineScreenRectangles ( base64Image , screenRectangleOptions ) ; const croppedBase64Image = await makeCroppedBase64Image ( { base64Image , rectangles , logLevel } ) ; const afterOptions = { actualFolder : folders . actualFolder , base64Image : croppedBase64Image , disableCSSAnimation , hideElements , hideScrollBars , filePath : { browserName : enrichedInstanceData . browserName , deviceName : enrichedInstanceData . deviceName , isMobile : enrichedInstanceData . isMobile , savePerInstance , } , fileName : { browserName : enrichedInstanceData . browserName , browserVersion : enrichedInstanceData . browserVersion , deviceName : enrichedInstanceData . deviceName , devicePixelRatio : enrichedInstanceData . dimensions . window . devicePixelRatio , formatImageName , isMobile : enrichedInstanceData . isMobile , isTestInBrowser : enrichedInstanceData . isTestInBrowser , logName : enrichedInstanceData . logName , name : enrichedInstanceData . name , outerHeight : enrichedInstanceData . dimensions . window . outerHeight , outerWidth : enrichedInstanceData . dimensions . window . outerWidth , platformName : enrichedInstanceData . platformName , platformVersion : enrichedInstanceData . platformVersion , screenHeight : enrichedInstanceData . dimensions . window . screenHeight , screenWidth : enrichedInstanceData . dimensions . window . screenWidth , tag , } , logLevel , platformName : instanceData . platformName , removeElements , } ; return afterScreenshot ( methods . executor , afterOptions ) ; }