Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #28 from wswebcreation/fix/reduce-css-calls
Browse files Browse the repository at this point in the history
fix: limit amount of custom css calls
  • Loading branch information
wswebcreation committed Jul 26, 2019
2 parents 30d5a41 + e339bbd commit 60e91fb
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 191 deletions.
2 changes: 2 additions & 0 deletions lib/commands/saveElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default async function saveElement(
const afterOptions: AfterScreenshotOptions = {
actualFolder: folders.actualFolder,
base64Image: croppedBase64Image,
disableCSSAnimation,
hideElements,
hideScrollBars,
filePath: {
Expand All @@ -94,6 +95,7 @@ export default async function saveElement(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
platformName: instanceData.platformName,
removeElements,
};

Expand Down
2 changes: 2 additions & 0 deletions lib/commands/saveFullPageScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default async function saveFullPageScreen(
const afterOptions = {
actualFolder: folders.actualFolder,
base64Image: fullPageBase64Image,
disableCSSAnimation,
hideElements,
hideScrollBars,
filePath: {
Expand All @@ -100,6 +101,7 @@ export default async function saveFullPageScreen(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
platformName: instanceData.platformName,
removeElements,
};

Expand Down
2 changes: 2 additions & 0 deletions lib/commands/saveScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default async function saveScreen(
const afterOptions: AfterScreenshotOptions = {
actualFolder: folders.actualFolder,
base64Image: croppedBase64Image,
disableCSSAnimation,
hideElements,
hideScrollBars,
filePath: {
Expand All @@ -91,6 +92,7 @@ export default async function saveScreen(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
platformName: instanceData.platformName,
removeElements,
};

Expand Down
4 changes: 4 additions & 0 deletions lib/helpers/afterScreenshot.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface AfterScreenshotOptions {
actualFolder: string;
// The image
base64Image: string;
// Disable all css animations
disableCSSAnimation: boolean;
// If scrollbars need to be hidden
hideScrollBars: boolean;
// The file path options
Expand All @@ -20,6 +22,8 @@ export interface AfterScreenshotOptions {
fileName: ScreenshotFileNameOptions;
// Elements that need to be hidden (visibility: hidden) before saving a screenshot
hideElements: HTMLElement[];
// The platform name of the instance
platformName: string;
// Elements that need to be removed (display: none) before saving a screenshot
removeElements: HTMLElement[];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers/afterScreenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('afterScreenshot', () => {
const options = {
actualFolder: folder,
base64Image: 'string',
disableCSSAnimation: false,
hideScrollBars: true,
filePath: {
browserName: 'browserName',
Expand All @@ -35,6 +36,7 @@ describe('afterScreenshot', () => {
tag: 'tag',
},
hideElements: [<HTMLElement><any>'<div></div>'],
platformName: '',
removeElements: [<HTMLElement><any>'<div></div>'],
};

Expand Down
15 changes: 12 additions & 3 deletions lib/helpers/afterScreenshot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hideScrollBars from '../clientSideScripts/hideScrollbars';
import removeCustomCss from '../clientSideScripts/removeCustomCss';
import {CUSTOM_CSS_ID} from './constants';
import {formatFileName, getAndCreatePath} from './utils';
import {checkIsMobile, formatFileName, getAndCreatePath} from './utils';
import {saveBase64Image} from '../methods/images';
import {join} from 'path';
import {Executor} from '../methods/methods.interface';
Expand All @@ -16,10 +16,12 @@ export default async function afterScreenshot(executor: Executor, options: After
const {
actualFolder,
base64Image,
disableCSSAnimation,
fileName: fileNameOptions,
filePath,
hideElements,
hideScrollBars: noScrollBars,
platformName,
removeElements,
} = options;

Expand All @@ -33,15 +35,22 @@ export default async function afterScreenshot(executor: Executor, options: After
await saveBase64Image(base64Image, join(path, fileName));

// Show the scrollbars again
await executor(hideScrollBars, !noScrollBars);
/* istanbul ignore else */
if (noScrollBars) {
await executor(hideScrollBars, !noScrollBars);
}

// Show elements again
/* istanbul ignore else */
if (hideElements.length > 0 || removeElements.length > 0) {
await executor(hideRemoveElements, {hide: hideElements, remove: removeElements}, false);
}

// Remove the custom set css
await executor(removeCustomCss, CUSTOM_CSS_ID);
/* istanbul ignore else */
if (disableCSSAnimation || checkIsMobile(platformName)) {
await executor(removeCustomCss, CUSTOM_CSS_ID);
}

// Return the needed data
return {
Expand Down
10 changes: 7 additions & 3 deletions lib/helpers/beforeScreenshot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hideScrollBars from '../clientSideScripts/hideScrollbars';
import setCustomCss from '../clientSideScripts/setCustomCss';
import {CUSTOM_CSS_ID} from './constants';
import {getAddressBarShadowPadding, getToolBarShadowPadding} from './utils';
import {checkIsMobile, getAddressBarShadowPadding, getToolBarShadowPadding} from './utils';
import getEnrichedInstanceData from '../methods/instanceData';
import {BeforeScreenshotOptions, BeforeScreenshotResult} from './beforeScreenshot.interface';
import {Executor} from '../methods/methods.interface';
Expand Down Expand Up @@ -35,15 +35,19 @@ export default async function beforeScreenshot(
const toolBarPadding = getToolBarShadowPadding({platformName, browserName, toolBarShadowPadding, addShadowPadding});

// Hide the scrollbars
await executor(hideScrollBars, noScrollBars);
if(noScrollBars) {
await executor(hideScrollBars, noScrollBars);
}

// Hide and or Remove elements
if (hideElements.length > 0 || removeElements.length > 0) {
await executor(hideRemoveElements, {hide: hideElements, remove: removeElements}, true);
}

// Set some custom css
await executor(setCustomCss, {addressBarPadding, disableCSSAnimation, id: CUSTOM_CSS_ID, toolBarPadding});
if (disableCSSAnimation || checkIsMobile(platformName)) {
await executor(setCustomCss, {addressBarPadding, disableCSSAnimation, id: CUSTOM_CSS_ID, toolBarPadding});
}

// Get all the needed instance data
const instanceOptions = {
Expand Down

0 comments on commit 60e91fb

Please sign in to comment.