This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
saveFullPageScreen.ts
113 lines (105 loc) · 4.86 KB
/
saveFullPageScreen.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import beforeScreenshot from '../helpers/beforeScreenshot';
import afterScreenshot from '../helpers/afterScreenshot';
import {getBase64FullPageScreenshotsData} from '../methods/screenshots';
import {makeFullPageBase64Image} from '../methods/images';
import {ScreenshotOutput} from '../helpers/afterScreenshot.interfaces';
import {Methods} from '../methods/methods.interface';
import {InstanceData} from '../methods/instanceData.interfaces';
import {Folders} from '../base.interface';
import {SaveFullPageOptions} from './fullPage.interfaces';
import {BeforeScreenshotOptions, BeforeScreenshotResult} from '../helpers/beforeScreenshot.interface';
import {FullPageScreenshotDataOptions, FullPageScreenshotsData} from '../methods/screenshots.interfaces';
/**
* Saves an image of the full page
*/
export default async function saveFullPageScreen(
methods: Methods,
instanceData: InstanceData,
folders: Folders,
tag: string,
saveFullPageOptions: SaveFullPageOptions,
): Promise<ScreenshotOutput> {
// 1a. Set some variables
const {addressBarShadowPadding, autoSaveBaseline, formatImageName, savePerInstance, toolBarShadowPadding} = saveFullPageOptions.wic;
// 1b. Set the method options to the right values
const disableCSSAnimation: boolean = 'disableCSSAnimation' in saveFullPageOptions.method
? saveFullPageOptions.method.disableCSSAnimation
: saveFullPageOptions.wic.disableCSSAnimation;
const hideScrollBars: boolean = 'hideScrollBars' in saveFullPageOptions.method
? saveFullPageOptions.method.hideScrollBars
: saveFullPageOptions.wic.hideScrollBars;
const fullPageScrollTimeout: number = 'fullPageScrollTimeout' in saveFullPageOptions.method
? saveFullPageOptions.method.fullPageScrollTimeout
: saveFullPageOptions.wic.fullPageScrollTimeout;
const hideElements: HTMLElement[] = saveFullPageOptions.method.hideElements || [];
const removeElements: HTMLElement[] = saveFullPageOptions.method.removeElements || [];
const hideAfterFirstScroll: HTMLElement[] = saveFullPageOptions.method.hideAfterFirstScroll || [];
// 2. Prepare the beforeScreenshot
const beforeOptions: BeforeScreenshotOptions = {
instanceData,
addressBarShadowPadding,
disableCSSAnimation,
hideElements,
noScrollBars: hideScrollBars,
removeElements,
toolBarShadowPadding,
};
const enrichedInstanceData: BeforeScreenshotResult = await beforeScreenshot(methods.executor, beforeOptions, true);
// 3. Fullpage screenshots are taken per scrolled viewport
const fullPageScreenshotOptions: FullPageScreenshotDataOptions = {
addressBarShadowPadding: enrichedInstanceData.addressBarShadowPadding,
devicePixelRatio: enrichedInstanceData.dimensions.window.devicePixelRatio,
fullPageScrollTimeout,
hideAfterFirstScroll,
innerHeight: enrichedInstanceData.dimensions.window.innerHeight,
isAndroid: enrichedInstanceData.isAndroid,
isAndroidChromeDriverScreenshot: enrichedInstanceData.isAndroidChromeDriverScreenshot,
isAndroidNativeWebScreenshot: enrichedInstanceData.isAndroidNativeWebScreenshot,
isIos: enrichedInstanceData.isIos,
toolBarShadowPadding: enrichedInstanceData.toolBarShadowPadding,
};
const screenshotsData: FullPageScreenshotsData = await getBase64FullPageScreenshotsData(
methods.screenShot,
methods.executor,
fullPageScreenshotOptions,
);
// 4. Make a fullpage base64 image
const fullPageBase64Image: string = await makeFullPageBase64Image(screenshotsData);
// 5. The after the screenshot methods
const afterOptions = {
actualFolder: folders.actualFolder,
base64Image: fullPageBase64Image,
disableCSSAnimation,
hideElements,
hideScrollBars,
filePath: {
autoSaveBaseline,
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,
},
platformName: instanceData.platformName,
removeElements,
};
// 6. Return the data
return afterScreenshot(methods.executor, afterOptions);
}