import { executeImageCompare } from '../methods/images' ; import { checkIsMobile } from '../helpers/utils' ; import saveElement from './saveElement' ; import { ImageCompareResult } from '../methods/images.interfaces' ; import { Methods } from '../methods/methods.interface' ; import { InstanceData } from '../methods/instanceData.interfaces' ; import { Folders } from '../base.interface' ; import { CheckElementOptions , SaveElementOptions } from './element.interfaces' ; import { methodCompareOptions } from '../helpers/options' ; /**
 * Compare  an image of the element
 */ export default async function checkElement ( methods , instanceData , folders , element , tag , checkElementOptions ) { const saveElementOptions = { wic : checkElementOptions . wic , method : { ... ( 'disableCSSAnimation' in checkElementOptions . method ? { disableCSSAnimation : checkElementOptions . method . disableCSSAnimation } : { } ) , ... ( 'hideScrollBars' in checkElementOptions . method ? { hideScrollBars : checkElementOptions . method . hideScrollBars } : { } ) , ... ( 'resizeDimensions' in checkElementOptions . method ? { resizeDimensions : checkElementOptions . method . resizeDimensions } : { } ) , ... { hideElements : checkElementOptions . method . hideElements || [ ] } , ... { removeElements : checkElementOptions . method . removeElements || [ ] } , } } ; const { devicePixelRatio , fileName } = await saveElement ( methods , instanceData , folders , element , tag , saveElementOptions ) ; const compareOptions = methodCompareOptions ( checkElementOptions . method ) ; const executeCompareOptions = { devicePixelRatio , compareOptions : { wic : checkElementOptions . wic . compareOptions , method : compareOptions , } , fileName , folderOptions : { autoSaveBaseline : checkElementOptions . wic . autoSaveBaseline , actualFolder : folders . actualFolder , baselineFolder : folders . baselineFolder , diffFolder : folders . diffFolder , browserName : instanceData . browserName , deviceName : instanceData . deviceName , isMobile : checkIsMobile ( instanceData . platformName ) , savePerInstance : checkElementOptions . wic . savePerInstance , } , isAndroidNativeWebScreenshot : instanceData . nativeWebScreenshot , isHybridApp : checkElementOptions . wic . isHybridApp , logLevel : checkElementOptions . wic . logLevel , platformName : instanceData . platformName , } ; return executeImageCompare ( methods . executor , executeCompareOptions ) ; }