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

Commit

Permalink
Merge a5ede11 into 1d691cf
Browse files Browse the repository at this point in the history
  • Loading branch information
wswebcreation committed Nov 8, 2020
2 parents 1d691cf + a5ede11 commit da061d5
Show file tree
Hide file tree
Showing 27 changed files with 2,448 additions and 2,297 deletions.
14 changes: 7 additions & 7 deletions docs/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ Delete runtime folder (`actual` & `diff`) on initialisation
> **NOTE:**<br>
> This will only work when the [`screenshotPath`](#screenshotpath) is set through the plugin options, and **WILL NOT WORK** when you set the folders in the methods
### `debug`
- **Type:** `boolean`
- **Mandatory:** No
- **Default:** `false`

Enable extra console logging or always saving the diff images during comparison.

### `disableCSSAnimation`
- **Type:** `boolean`
- **Mandatory:** No
Expand Down Expand Up @@ -105,6 +98,13 @@ Hide scrollbars in the application. If set to true all scrollbars will be disabl

Tell the module if the used app is an Hybrid app, this will not calculate the address bar height because it is not there.

### `logLevel`
- **Type:** `string`
- **Mandatory:** No
- **Default:** `info`

Adds extra logs, options are `debug | info | warn | error | silent`

### `savePerInstance`
- **Type:** `boolean`
- **Default:** `false`
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/checkElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default async function checkElement(
// 2a. Determine the options
const compareOptions = methodCompareOptions(checkElementOptions.method);
const executeCompareOptions = {
debug: checkElementOptions.wic.debug,
devicePixelRatio,
compareOptions: {
wic: checkElementOptions.wic.compareOptions,
Expand All @@ -55,6 +54,7 @@ export default async function checkElement(
},
isAndroidNativeWebScreenshot: instanceData.nativeWebScreenshot,
isHybridApp: checkElementOptions.wic.isHybridApp,
logLevel: checkElementOptions.wic.logLevel,
platformName: instanceData.platformName,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/checkFullPageScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default async function checkFullPageScreen(
// 2a. Determine the options
const compareOptions = methodCompareOptions(checkFullPageOptions.method);
const executeCompareOptions = {
debug: checkFullPageOptions.wic.debug,
devicePixelRatio,
compareOptions: {
wic: checkFullPageOptions.wic.compareOptions,
Expand All @@ -63,6 +62,7 @@ export default async function checkFullPageScreen(
},
isAndroidNativeWebScreenshot: instanceData.nativeWebScreenshot,
isHybridApp: checkFullPageOptions.wic.isHybridApp,
logLevel: checkFullPageOptions.wic.logLevel,
platformName: instanceData.platformName,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/checkScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default async function checkScreen(
// 2a. Determine the compare options
const methodCompareOptions = screenMethodCompareOptions(checkScreenOptions.method);
const executeCompareOptions: ImageCompareOptions = {
debug: checkScreenOptions.wic.debug,
devicePixelRatio,
compareOptions: {
wic: checkScreenOptions.wic.compareOptions,
Expand All @@ -51,6 +50,7 @@ export default async function checkScreen(
isMobile: checkIsMobile(instanceData.platformName),
savePerInstance: checkScreenOptions.wic.savePerInstance,
},
logLevel: checkScreenOptions.wic.logLevel,
isAndroidNativeWebScreenshot: instanceData.nativeWebScreenshot,
isHybridApp: checkScreenOptions.wic.isHybridApp,
platformName: instanceData.platformName,
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/saveElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function saveElement(
): Promise<ScreenshotOutput> {

// 1a. Set some variables
const {addressBarShadowPadding, formatImageName, savePerInstance, toolBarShadowPadding} = saveElementOptions.wic;
const {addressBarShadowPadding, formatImageName, logLevel, savePerInstance, toolBarShadowPadding} = saveElementOptions.wic;

// 1b. Set the method options to the right values
const disableCSSAnimation: boolean = 'disableCSSAnimation' in saveElementOptions.method
Expand All @@ -45,6 +45,7 @@ export default async function saveElement(
addressBarShadowPadding,
disableCSSAnimation,
hideElements,
logLevel,
noScrollBars: hideScrollBars,
removeElements,
toolBarShadowPadding,
Expand All @@ -65,7 +66,7 @@ export default async function saveElement(
const rectangles: RectanglesOutput = await determineElementRectangles(methods.executor, screenshot, elementRectangleOptions, element);

// 5. Make a cropped base64 image with resizeDimensions
const croppedBase64Image = await makeCroppedBase64Image(screenshot, rectangles, resizeDimensions);
const croppedBase64Image = await makeCroppedBase64Image(screenshot, rectangles, logLevel, resizeDimensions);

// 6. The after the screenshot methods
const afterOptions: AfterScreenshotOptions = {
Expand Down Expand Up @@ -98,6 +99,7 @@ export default async function saveElement(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
logLevel,
platformName: instanceData.platformName,
removeElements,
};
Expand Down
4 changes: 4 additions & 0 deletions lib/commands/saveFullPageScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default async function saveFullPageScreen(
autoSaveBaseline,
formatImageName,
isHybridApp,
logLevel,
savePerInstance,
toolBarShadowPadding,
} = saveFullPageOptions.wic;
Expand All @@ -51,6 +52,7 @@ export default async function saveFullPageScreen(
addressBarShadowPadding,
disableCSSAnimation,
hideElements,
logLevel,
noScrollBars: hideScrollBars,
removeElements,
toolBarShadowPadding,
Expand All @@ -69,6 +71,7 @@ export default async function saveFullPageScreen(
isAndroidNativeWebScreenshot: enrichedInstanceData.isAndroidNativeWebScreenshot,
isHybridApp,
isIos: enrichedInstanceData.isIos,
logLevel: logLevel,
toolBarShadowPadding: enrichedInstanceData.toolBarShadowPadding,
};
const screenshotsData: FullPageScreenshotsData = await getBase64FullPageScreenshotsData(
Expand Down Expand Up @@ -112,6 +115,7 @@ export default async function saveFullPageScreen(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
logLevel,
platformName: instanceData.platformName,
removeElements,
};
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/saveScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function saveScreen(
): Promise<ScreenshotOutput> {

// 1a. Set some variables
const {addressBarShadowPadding, formatImageName, savePerInstance, toolBarShadowPadding} = saveScreenOptions.wic;
const {addressBarShadowPadding, formatImageName, logLevel, savePerInstance, toolBarShadowPadding} = saveScreenOptions.wic;

// 1b. Set the method options to the right values
const disableCSSAnimation: boolean = 'disableCSSAnimation' in saveScreenOptions.method
Expand All @@ -41,6 +41,7 @@ export default async function saveScreen(
addressBarShadowPadding,
disableCSSAnimation,
hideElements,
logLevel,
noScrollBars: hideScrollBars,
removeElements,
toolBarShadowPadding,
Expand All @@ -62,7 +63,7 @@ export default async function saveScreen(
const rectangles: RectanglesOutput = determineScreenRectangles(screenshot, screenRectangleOptions);

// 4. Make a cropped base64 image
const croppedBase64Image: string = await makeCroppedBase64Image(screenshot, rectangles);
const croppedBase64Image: string = await makeCroppedBase64Image(screenshot, rectangles, logLevel);

// 5. The after the screenshot methods
const afterOptions: AfterScreenshotOptions = {
Expand Down Expand Up @@ -95,6 +96,7 @@ export default async function saveScreen(
screenWidth: enrichedInstanceData.dimensions.window.screenWidth,
tag,
},
logLevel,
platformName: instanceData.platformName,
removeElements,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/screen.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DefaultOptions} from '../helpers/options.interface';
import {DefaultOptions, LogLevel} from '../helpers/options.interface';
import {CheckMethodOptions} from './check.interfaces';

export interface SaveScreenOptions {
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/__snapshots__/options.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Object {
"saveAboveTolerance": 0,
"scaleImagesToSameSize": false,
},
"debug": false,
"disableCSSAnimation": false,
"formatImageName": "{tag}-{browserName}-{width}x{height}-dpr-{dpr}",
"fullPageScrollTimeout": 1500,
"hideScrollBars": true,
"isHybridApp": false,
"logLevel": "info",
"savePerInstance": false,
"tabbableOptions": Object {
"circle": Object {
Expand Down Expand Up @@ -63,12 +63,12 @@ Object {
"saveAboveTolerance": 12,
"scaleImagesToSameSize": true,
},
"debug": true,
"disableCSSAnimation": true,
"formatImageName": "{foo}-{bar}",
"fullPageScrollTimeout": 12345,
"hideScrollBars": true,
"isHybridApp": false,
"logLevel": "info",
"savePerInstance": true,
"tabbableOptions": Object {
"circle": Object {
Expand Down
4 changes: 4 additions & 0 deletions lib/helpers/afterScreenshot.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {LogLevel} from "./options.interface";

export interface ScreenshotOutput {
// The device pixel ratio of the instance
devicePixelRatio: number;
Expand All @@ -22,6 +24,8 @@ export interface AfterScreenshotOptions {
fileName: ScreenshotFileNameOptions;
// Elements that need to be hidden (visibility: hidden) before saving a screenshot
hideElements: (HTMLElement | HTMLElement[])[];
// Level to show logs
logLevel: LogLevel;
// The platform name of the instance
platformName: string;
// Elements that need to be removed (display: none) before saving a screenshot
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers/afterScreenshot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import afterScreenshot from './afterScreenshot';
import {join} from 'path';
import {removeSync} from 'fs-extra';
import {LogLevel} from "./options.interface";

describe('afterScreenshot', () => {
const folder = join(process.cwd(), '/.tmp/afterScreenshot');
Expand Down Expand Up @@ -38,6 +39,7 @@ describe('afterScreenshot', () => {
screenWidth: 1440,
tag: 'tag',
},
logLevel: LogLevel.debug,
hideElements: [<HTMLElement><any>'<div></div>'],
platformName: '',
removeElements: [<HTMLElement><any>'<div></div>'],
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers/afterScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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
Expand All @@ -22,6 +23,7 @@ export default async function afterScreenshot(executor: Executor, options: After
filePath,
hideElements,
hideScrollBars: noScrollBars,
logLevel,
platformName,
removeElements,
} = options;
Expand All @@ -47,7 +49,8 @@ export default async function afterScreenshot(executor: Executor, options: After
try {
await executor(hideRemoveElements, {hide: hideElements, remove: removeElements}, false);
} catch (e) {
console.log(yellow(`
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
Expand All @@ -56,6 +59,7 @@ export default async function afterScreenshot(executor: Executor, options: After
We made sure the test didn't break.
#####################################################################################
`));
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/helpers/beforeScreenshot.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {EnrichedInstanceData, InstanceData} from '../methods/instanceData.interfaces';
import {LogLevel} from "./options.interface";

export interface BeforeScreenshotOptions {
// The instance data
Expand All @@ -7,6 +8,8 @@ export interface BeforeScreenshotOptions {
addressBarShadowPadding: number;
// Disable all css animations
disableCSSAnimation: boolean;
// Level to show logs
logLevel: LogLevel;
// Hide all scrollbars
noScrollBars: boolean;
// The padding that needs to be added to the tool bar on iOS and Android
Expand Down
3 changes: 3 additions & 0 deletions lib/helpers/beforeScreenshot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import beforeScreenshot from './beforeScreenshot';
import {LogLevel} from "./options.interface";

describe('beforeScreenshot', () => {
it('should be able to return the enriched instance data with default options', async () => {
Expand All @@ -17,6 +18,7 @@ describe('beforeScreenshot', () => {
},
addressBarShadowPadding: 6,
disableCSSAnimation: true,
logLevel: LogLevel.debug,
noScrollBars: true,
toolBarShadowPadding: 6,
hideElements: [<HTMLElement><any>'<div></div>'],
Expand All @@ -43,6 +45,7 @@ describe('beforeScreenshot', () => {
addressBarShadowPadding: 6,
disableCSSAnimation: true,
noScrollBars: true,
logLevel: LogLevel.debug,
toolBarShadowPadding: 6,
hideElements: [<HTMLElement><any>'<div></div>'],
removeElements: [<HTMLElement><any>'<div></div>'],
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers/beforeScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {BeforeScreenshotOptions, BeforeScreenshotResult} from './beforeScreensho
import {Executor} from '../methods/methods.interface';
import hideRemoveElements from '../clientSideScripts/hideRemoveElements';
import {yellow} from "chalk";
import {LogLevel} from "./options.interface";

/**
* Methods that need to be executed before a screenshot will be taken
Expand All @@ -22,6 +23,7 @@ export default async function beforeScreenshot(
addressBarShadowPadding,
disableCSSAnimation,
hideElements,
logLevel,
noScrollBars,
removeElements,
toolBarShadowPadding,
Expand All @@ -45,7 +47,8 @@ export default async function beforeScreenshot(
try {
await executor(hideRemoveElements, {hide: hideElements, remove: removeElements}, true);
} catch (e) {
console.log(yellow(`
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
Expand All @@ -54,6 +57,7 @@ export default async function beforeScreenshot(
We made sure the test didn't break.
#####################################################################################
`));
}
}
}

Expand Down
9 changes: 0 additions & 9 deletions lib/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ export const DEFAULT_RESIZE_DIMENSIONS = {
left: 0
};
export const FULL_PAGE_SCROLL_TIMEOUT = 1500;
export const LOG_METHODS = ['error', 'warn', 'info', 'debug', 'trace', 'silent'];
export const LOG_LEVELS = {
ERROR: 'error',
WARN: 'warn',
INFO: 'info',
DEBUG: 'debug',
TRACE: 'trace',
SILENT: 'silent',
};
const androidDefaultOffsets = {
STATUS_BAR: 24,
ADDRESS_BAR: 56,
Expand Down

0 comments on commit da061d5

Please sign in to comment.