@o3r/testing 10.0.0-next.9 → 11.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/core/angular/component-fixture.d.ts +0 -15
- package/core/angular/component-fixture.d.ts.map +1 -1
- package/core/angular/component-fixture.js +11 -20
- package/core/angular/component-fixture.js.map +1 -1
- package/core/angular/element.d.ts +0 -1
- package/core/angular/element.d.ts.map +1 -1
- package/core/angular/element.js +0 -1
- package/core/angular/element.js.map +1 -1
- package/core/angular-materials/autocomplete-material.d.ts +0 -1
- package/core/angular-materials/autocomplete-material.d.ts.map +1 -1
- package/core/angular-materials/autocomplete-material.js +0 -1
- package/core/angular-materials/autocomplete-material.js.map +1 -1
- package/core/angular-materials/select-material.d.ts +0 -7
- package/core/angular-materials/select-material.d.ts.map +1 -1
- package/core/angular-materials/select-material.js +0 -9
- package/core/angular-materials/select-material.js.map +1 -1
- package/core/component-fixture.d.ts +20 -12
- package/core/component-fixture.d.ts.map +1 -1
- package/core/component-fixture.js +18 -5
- package/core/component-fixture.js.map +1 -1
- package/core/elements/checkbox-element.d.ts +0 -1
- package/core/elements/checkbox-element.d.ts.map +1 -1
- package/core/elements/checkbox-element.js.map +1 -1
- package/core/elements/radio-element.d.ts +0 -1
- package/core/elements/radio-element.d.ts.map +1 -1
- package/core/elements/radio-element.js.map +1 -1
- package/core/elements/select-element.d.ts +0 -2
- package/core/elements/select-element.d.ts.map +1 -1
- package/core/elements/select-element.js +0 -2
- package/core/elements/select-element.js.map +1 -1
- package/core/helpers.d.ts +0 -2
- package/core/helpers.d.ts.map +1 -1
- package/core/helpers.js +0 -2
- package/core/helpers.js.map +1 -1
- package/core/page-fixture.d.ts +0 -1
- package/core/page-fixture.d.ts.map +1 -1
- package/core/page-fixture.js +0 -1
- package/core/page-fixture.js.map +1 -1
- package/core/playwright/component-fixture.d.ts +0 -15
- package/core/playwright/component-fixture.d.ts.map +1 -1
- package/core/playwright/component-fixture.js +14 -24
- package/core/playwright/component-fixture.js.map +1 -1
- package/core/playwright/element.d.ts +0 -2
- package/core/playwright/element.d.ts.map +1 -1
- package/core/playwright/element.js +0 -1
- package/core/playwright/element.js.map +1 -1
- package/core/protractor/component-fixture.d.ts +0 -15
- package/core/protractor/component-fixture.d.ts.map +1 -1
- package/core/protractor/component-fixture.js +11 -21
- package/core/protractor/component-fixture.js.map +1 -1
- package/core/protractor/utils.d.ts +0 -1
- package/core/protractor/utils.d.ts.map +1 -1
- package/core/protractor/utils.js +0 -1
- package/core/protractor/utils.js.map +1 -1
- package/kassette/update-dates-in-mocks.d.ts +0 -3
- package/kassette/update-dates-in-mocks.d.ts.map +1 -1
- package/kassette/update-dates-in-mocks.js +10 -6
- package/kassette/update-dates-in-mocks.js.map +1 -1
- package/localization/localization-mock.d.ts +0 -1
- package/localization/localization-mock.d.ts.map +1 -1
- package/localization/localization-mock.js +4 -3
- package/localization/localization-mock.js.map +1 -1
- package/mocks/mock-component-generator.d.ts +5 -4
- package/mocks/mock-component-generator.d.ts.map +1 -1
- package/mocks/mock-component-generator.js +5 -9
- package/mocks/mock-component-generator.js.map +1 -1
- package/package.json +65 -54
- package/schematics/add-functions-to-fixture/index.js +1 -1
- package/schematics/add-functions-to-fixture/index.js.map +1 -1
- package/schematics/add-functions-to-fixture/schema.json +1 -1
- package/schematics/fixture-to-component/index.d.ts.map +1 -1
- package/schematics/fixture-to-component/index.js +1 -1
- package/schematics/fixture-to-component/index.js.map +1 -1
- package/schematics/fixture-to-component/schema.json +1 -1
- package/schematics/ng-add/fixture/index.d.ts +2 -1
- package/schematics/ng-add/fixture/index.d.ts.map +1 -1
- package/schematics/ng-add/fixture/index.js +43 -16
- package/schematics/ng-add/fixture/index.js.map +1 -1
- package/schematics/ng-add/index.d.ts +0 -1
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +17 -18
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/playwright/index.d.ts +0 -1
- package/schematics/ng-add/playwright/index.d.ts.map +1 -1
- package/schematics/ng-add/playwright/index.js +1 -2
- package/schematics/ng-add/playwright/index.js.map +1 -1
- package/schematics/ng-add/schema.json +2 -2
- package/schematics/ng-add/templates/project/jest.config.js.template +1 -1
- package/schematics/ng-add/templates/workspace/jest.config.js.template +1 -1
- package/schematics/ng-add/templates/workspace/jest.config.ut.js.template +53 -41
- package/schematics/playwright/sanity/index.d.ts +0 -1
- package/schematics/playwright/sanity/index.d.ts.map +1 -1
- package/schematics/playwright/sanity/index.js +2 -4
- package/schematics/playwright/sanity/index.js.map +1 -1
- package/schematics/playwright/sanity/schema.json +1 -1
- package/schematics/playwright/scenario/index.d.ts +0 -1
- package/schematics/playwright/scenario/index.d.ts.map +1 -1
- package/schematics/playwright/scenario/index.js +2 -4
- package/schematics/playwright/scenario/index.js.map +1 -1
- package/schematics/playwright/scenario/schema.json +1 -1
- package/store/testable-select.d.ts +0 -3
- package/store/testable-select.d.ts.map +1 -1
- package/store/testable-select.js +0 -6
- package/store/testable-select.js.map +1 -1
- package/store/typings.d.ts +0 -1
- package/store/typings.d.ts.map +1 -1
- package/store/typings.js +0 -1
- package/store/typings.js.map +1 -1
- package/tools/path-replacement/path-replacement.d.ts +0 -1
- package/tools/path-replacement/path-replacement.d.ts.map +1 -1
- package/tools/path-replacement/path-replacement.js +0 -1
- package/tools/path-replacement/path-replacement.js.map +1 -1
- package/tools/protractor/fetch-manager/_fetch-manager.js +0 -1
- package/tools/protractor/fetch-manager/_fetch-manager.js.map +1 -1
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.js +0 -4
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.js.map +1 -1
- package/tools/protractor/post-message-interceptor/post-message-interceptor.d.ts +0 -4
- package/tools/protractor/post-message-interceptor/post-message-interceptor.d.ts.map +1 -1
- package/tools/protractor/post-message-interceptor/post-message-interceptor.js +0 -4
- package/tools/protractor/post-message-interceptor/post-message-interceptor.js.map +1 -1
- package/visual-test/utils.d.ts +0 -2
- package/visual-test/utils.d.ts.map +1 -1
- package/visual-test/utils.js +0 -2
- package/visual-test/utils.js.map +1 -1
- package/visual-test/visual-test.d.ts +1 -5
- package/visual-test/visual-test.d.ts.map +1 -1
- package/visual-test/visual-test.js +1 -5
- package/visual-test/visual-test.js.map +1 -1
|
@@ -6,14 +6,12 @@ export declare class PostMessageInterceptor {
|
|
|
6
6
|
private readonly GET_INSTANCE;
|
|
7
7
|
/**
|
|
8
8
|
* Executes a script in the app
|
|
9
|
-
*
|
|
10
9
|
* @param methodName
|
|
11
10
|
* @param {...any} args
|
|
12
11
|
*/
|
|
13
12
|
private execInstanceMethod;
|
|
14
13
|
/**
|
|
15
14
|
* Executes an async script in the app
|
|
16
|
-
*
|
|
17
15
|
* @param methodName
|
|
18
16
|
* @param {...any} args
|
|
19
17
|
*/
|
|
@@ -29,7 +27,6 @@ export declare class PostMessageInterceptor {
|
|
|
29
27
|
stop(): Promise<void>;
|
|
30
28
|
/**
|
|
31
29
|
* Listens for post messages
|
|
32
|
-
*
|
|
33
30
|
* @param conditionFn an optional boolean function that will evaluate if the message should be saved or not in the stack
|
|
34
31
|
*/
|
|
35
32
|
listen(conditionFn?: ConditionFn): Promise<void>;
|
|
@@ -39,7 +36,6 @@ export declare class PostMessageInterceptor {
|
|
|
39
36
|
stopListening(): Promise<void>;
|
|
40
37
|
/**
|
|
41
38
|
* Get all the post messages
|
|
42
|
-
*
|
|
43
39
|
* @param timeoutInterval Interval in milliseconds between two checks
|
|
44
40
|
* @param retries How many retries to be executed (-1 for infinite retries)
|
|
45
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-message-interceptor.d.ts","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/post-message-interceptor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEtD;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiD;IAE9E
|
|
1
|
+
{"version":3,"file":"post-message-interceptor.d.ts","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/post-message-interceptor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEtD;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiD;IAE9E;;;;OAIG;YACW,kBAAkB;IAIhC;;;;OAIG;YACW,uBAAuB;IAIrC;;;OAGG;IACU,UAAU;IAWvB;;OAEG;IACU,IAAI;IAIjB;;;OAGG;IACU,MAAM,CAAC,WAAW,CAAC,EAAE,WAAW;IAI7C;;OAEG;IACU,aAAa;IAI1B;;;;OAIG;IACU,WAAW,CAAC,eAAe,SAAM,EAAE,OAAO,SAAK,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAG1F"}
|
|
@@ -14,7 +14,6 @@ var PostMessageInterceptor = /** @class */ (function () {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Executes a script in the app
|
|
17
|
-
*
|
|
18
17
|
* @param methodName
|
|
19
18
|
* @param {...any} args
|
|
20
19
|
*/
|
|
@@ -34,7 +33,6 @@ var PostMessageInterceptor = /** @class */ (function () {
|
|
|
34
33
|
};
|
|
35
34
|
/**
|
|
36
35
|
* Executes an async script in the app
|
|
37
|
-
*
|
|
38
36
|
* @param methodName
|
|
39
37
|
* @param {...any} args
|
|
40
38
|
*/
|
|
@@ -93,7 +91,6 @@ var PostMessageInterceptor = /** @class */ (function () {
|
|
|
93
91
|
};
|
|
94
92
|
/**
|
|
95
93
|
* Listens for post messages
|
|
96
|
-
*
|
|
97
94
|
* @param conditionFn an optional boolean function that will evaluate if the message should be saved or not in the stack
|
|
98
95
|
*/
|
|
99
96
|
PostMessageInterceptor.prototype.listen = function (conditionFn) {
|
|
@@ -125,7 +122,6 @@ var PostMessageInterceptor = /** @class */ (function () {
|
|
|
125
122
|
};
|
|
126
123
|
/**
|
|
127
124
|
* Get all the post messages
|
|
128
|
-
*
|
|
129
125
|
* @param timeoutInterval Interval in milliseconds between two checks
|
|
130
126
|
* @param retries How many retries to be executed (-1 for infinite retries)
|
|
131
127
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-message-interceptor.js","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/post-message-interceptor.ts"],"names":[],"mappings":";;;;AAAA,4BAA8B;AAC9B,gCAAkC;AAClC,yCAAqC;AAIrC;;GAEG;AACH;IAAA;QACmB,iBAAY,GAAG,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"post-message-interceptor.js","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/post-message-interceptor.ts"],"names":[],"mappings":";;;;AAAA,4BAA8B;AAC9B,gCAAkC;AAClC,yCAAqC;AAIrC;;GAEG;AACH;IAAA;QACmB,iBAAY,GAAG,6CAA6C,CAAC;IAiEhF,CAAC;IA/DC;;;;OAIG;IACW,mDAAkB,GAAhC,UAAiC,UAAkB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;;;;4BAC1D,qBAAM,oBAAO,CAAC,aAAa,OAArB,oBAAO,yBAAe,UAAG,IAAI,CAAC,YAAY,cAAI,UAAU,oBAAiB,GAAK,IAAI,WAAC;4BAAhG,sBAAO,SAAyF,EAAC;;;;KAClG;IAED;;;;OAIG;IACW,wDAAuB,GAArC,UAAsC,UAAkB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;;;;4BAC/D,qBAAM,oBAAO,CAAC,kBAAkB,OAA1B,oBAAO,yBAAoB,UAAG,IAAI,CAAC,YAAY,cAAI,UAAU,oBAAiB,GAAK,IAAI,WAAC;4BAArG,sBAAO,SAA8F,EAAC;;;;KACvG;IAED;;;OAGG;IACU,2CAAU,GAAvB;;;;;;wBACQ,YAAY,GAAG,EAAE,CAAC,YAAY,CAClC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,8BAA8B,CAAC,EACjJ;4BACE,QAAQ,EAAE,OAAO;yBAClB,CACF,CAAC;wBACF,qBAAM,oBAAO,CAAC,aAAa,CAAC,YAAY,CAAC,EAAA;;wBAAzC,SAAyC,CAAC;wBAC1C,qBAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAA;;wBAArC,SAAqC,CAAC;;;;;KACvC;IAED;;OAEG;IACU,qCAAI,GAAjB;;;;4BACE,qBAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAA;;wBAArC,SAAqC,CAAC;;;;;KACvC;IAED;;;OAGG;IACU,uCAAM,GAAnB,UAAoB,WAAyB;;;;4BAC3C,qBAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAA;;wBAApD,SAAoD,CAAC;;;;;KACtD;IAED;;OAEG;IACU,8CAAa,GAA1B;;;;4BACE,qBAAM,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAA;;wBAA9C,SAA8C,CAAC;;;;;KAChD;IAED;;;;OAIG;IACU,4CAAW,GAAxB,UAAyB,eAAqB,EAAE,OAAY;QAAnC,gCAAA,EAAA,qBAAqB;QAAE,wBAAA,EAAA,WAAW,CAAC;;;;4BAClD,qBAAM,IAAI,CAAC,uBAAuB,CAAC,aAAa,EAAE,eAAe,EAAE,OAAO,CAAC,EAAA;4BAAnF,sBAAO,CAAC,SAA2E,CAAsB,EAAC;;;;KAC3G;IACH,6BAAC;AAAD,CAAC,AAlED,IAkEC;AAlEY,wDAAsB","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { browser } from 'protractor';\n\nimport { ConditionFn, PostMessageCall } from './core';\n\n/**\n * Controls the postMessage interceptor\n */\nexport class PostMessageInterceptor {\n private readonly GET_INSTANCE = 'window.postMessageInterceptor.getInstance()';\n\n /**\n * Executes a script in the app\n * @param methodName\n * @param {...any} args\n */\n private async execInstanceMethod(methodName: string, ...args: any[]) {\n return await browser.executeScript(`${this.GET_INSTANCE}.${methodName}(...arguments);`, ...args);\n }\n\n /**\n * Executes an async script in the app\n * @param methodName\n * @param {...any} args\n */\n private async execInstanceAsyncMethod(methodName: string, ...args: any[]) {\n return await browser.executeAsyncScript(`${this.GET_INSTANCE}.${methodName}(...arguments);`, ...args);\n }\n\n /**\n * Initializes the PostMessageInterceptor in the app\n * NOTE: It does not start listening right away. You need to call listen()\n */\n public async initialize() {\n const fetchManager = fs.readFileSync(\n path.resolve(process.cwd(), 'node_modules', '@o3r', 'testing', 'tools', 'protractor', 'post-message-interceptor', '_post-message-interceptor.js'),\n {\n encoding: 'utf-8'\n }\n );\n await browser.executeScript(fetchManager);\n await this.execInstanceMethod('init');\n }\n\n /**\n * Stops the PostMessageInterceptor.\n */\n public async stop() {\n await this.execInstanceMethod('stop');\n }\n\n /**\n * Listens for post messages\n * @param conditionFn an optional boolean function that will evaluate if the message should be saved or not in the stack\n */\n public async listen(conditionFn?: ConditionFn) {\n await this.execInstanceMethod('listen', conditionFn);\n }\n\n /**\n * Stops listening for post messages, resets the stack and clears the condition\n */\n public async stopListening() {\n await this.execInstanceMethod('stopListening');\n }\n\n /**\n * Get all the post messages\n * @param timeoutInterval Interval in milliseconds between two checks\n * @param retries How many retries to be executed (-1 for infinite retries)\n */\n public async getMessages(timeoutInterval = 100, retries = -1): Promise<PostMessageCall[]> {\n return (await this.execInstanceAsyncMethod('getMessages', timeoutInterval, retries)) as PostMessageCall[];\n }\n}\n"]}
|
package/visual-test/utils.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Prepare css rule to hide specific blocks
|
|
3
3
|
*
|
|
4
4
|
* Should be called only once during the visual test.
|
|
5
|
-
*
|
|
6
5
|
* @note: this function is evaluated in the context of the page and should not use external variables
|
|
7
6
|
* @param ignoreClass
|
|
8
7
|
*/
|
|
@@ -13,7 +12,6 @@ export declare function prepareVisualTesting(ignoreClass?: string): void;
|
|
|
13
12
|
export declare function isVisualTestingEnabled(): boolean;
|
|
14
13
|
/**
|
|
15
14
|
* Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
|
|
16
|
-
*
|
|
17
15
|
* @note: this function is evaluated in the context of the page and cannot use external code
|
|
18
16
|
* @param enabled
|
|
19
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,SAAe,QAkB9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,YAGrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QAOzD"}
|
package/visual-test/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ exports.toggleVisualTestingRender = exports.isVisualTestingEnabled = exports.pre
|
|
|
5
5
|
* Prepare css rule to hide specific blocks
|
|
6
6
|
*
|
|
7
7
|
* Should be called only once during the visual test.
|
|
8
|
-
*
|
|
9
8
|
* @note: this function is evaluated in the context of the page and should not use external variables
|
|
10
9
|
* @param ignoreClass
|
|
11
10
|
*/
|
|
@@ -27,7 +26,6 @@ function isVisualTestingEnabled() {
|
|
|
27
26
|
exports.isVisualTestingEnabled = isVisualTestingEnabled;
|
|
28
27
|
/**
|
|
29
28
|
* Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
|
|
30
|
-
*
|
|
31
29
|
* @note: this function is evaluated in the context of the page and cannot use external code
|
|
32
30
|
* @param enabled
|
|
33
31
|
*/
|
package/visual-test/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,WAA0B;IAA1B,4BAAA,EAAA,0BAA0B;IAC7D,IAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzD,IAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,gBAAgB,CAAC,WAAW,GAAG,iBAC1B,kBAAkB,eAAK,WAAW,4CAElC,kBAAkB,eAAK,WAAW,wLASrC,CAAC;IAEH,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC;AAlBD,oDAkBC;AAED;;GAEG;AACH,SAAgB,sBAAsB;IACpC,IAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;AAC9D,CAAC;AAHD,wDAGC;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,OAAgB;IACxD,IAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,IAAI,OAAO,EAAE;QACX,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;KACjD;SAAM;QACL,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;KACpD;AACH,CAAC;AAPD,8DAOC","sourcesContent":["/**\n * Prepare css rule to hide specific blocks\n *\n * Should be called only once during the visual test.\n * @note: this function is evaluated in the context of the page and should not use external variables\n * @param ignoreClass\n */\nexport function prepareVisualTesting(ignoreClass = 'e2e-ignore') {\n const visualTestingCss = document.createElement('style');\n const visualTestingClass = 'visual-testing-render';\n visualTestingCss.textContent = `\n .${visualTestingClass} .${ignoreClass} {position: relative;}\n\n .${visualTestingClass} .${ignoreClass}:before {\n z-index: 999;\n content: '';\n width: 100%;\n height: 100%;\n background: grey;\n position: absolute;\n left: 0;\n top: 0;\n }`;\n\n document.head.appendChild(visualTestingCss);\n}\n\n/**\n * Determine if the visual testing is enabled\n */\nexport function isVisualTestingEnabled() {\n const visualTestingClass = 'visual-testing-render';\n return document.body.classList.contains(visualTestingClass);\n}\n\n/**\n * Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.\n * @note: this function is evaluated in the context of the page and cannot use external code\n * @param enabled\n */\nexport function toggleVisualTestingRender(enabled: boolean) {\n const visualTestingClass = 'visual-testing-render';\n if (enabled) {\n document.body.classList.add(visualTestingClass);\n } else {\n document.body.classList.remove(visualTestingClass);\n }\n}\n"]}
|
|
@@ -50,8 +50,7 @@ export declare function toBeVisuallySimilar(): {
|
|
|
50
50
|
* It will create a file for the passed screenshot object.
|
|
51
51
|
* The path of the new file will be calculated using the parameters
|
|
52
52
|
* Ex: ./dist-screenshots\OWBooking\windows_chrome_91\fare-page-after-click-on-continue-0.png
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png
|
|
55
54
|
* @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()
|
|
56
55
|
* @param scenarioName E2e Scenario class name
|
|
57
56
|
* @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`
|
|
@@ -62,7 +61,6 @@ export declare function saveScreenshot(screenshot: string, scenarioName: string,
|
|
|
62
61
|
/**
|
|
63
62
|
* Write the 3 images (base/new/diff) on the reports folder
|
|
64
63
|
* The path inside the reports forlder will be calculated using the parameters
|
|
65
|
-
*
|
|
66
64
|
* @param pathToScenarioReport Path where the scenario report is saved inside reports folder
|
|
67
65
|
* @param screenshotsDirName Name of the directory which will contain the 3 images
|
|
68
66
|
* @param diff diff image
|
|
@@ -72,7 +70,6 @@ export declare function saveScreenshot(screenshot: string, scenarioName: string,
|
|
|
72
70
|
export declare function writeScreenshotsDiff(pathToScenarioReport: string, screenshotsDirName: string, diff: PNG, baseImage: PNG, currentImg: PNG): void;
|
|
73
71
|
/**
|
|
74
72
|
* Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario
|
|
75
|
-
*
|
|
76
73
|
* @param screenshot Actual captured screenshot object
|
|
77
74
|
* @param baseImagePath The path to the base screenshot
|
|
78
75
|
* @param threshold The diff between base screenshot and the current one should not be bigger than this value.
|
|
@@ -82,7 +79,6 @@ export declare function writeScreenshotsDiff(pathToScenarioReport: string, scree
|
|
|
82
79
|
export declare function compareScreenshot(screenshot: string, baseImagePath: string, threshold: number, pathToScenarioReport: string): VisualTestResult;
|
|
83
80
|
/**
|
|
84
81
|
* Helper function to perform a visual test operation
|
|
85
|
-
*
|
|
86
82
|
* @param screenshotObj Ex: for protractor browser.takeScreenshot()
|
|
87
83
|
* @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end
|
|
88
84
|
* @param device os followed by browser version - ex: `Windows 10 chrome 89`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-test.d.ts","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAG1B,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,eAAe,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,YAAY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tC,0FAA0F;IAC1F,sBAAsB,CAAC,EAAE;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAC,CAAC;IACtD,6GAA6G;IAC7G,IAAI,CAAC,EAAE;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAC,CAAC;IACvE,yCAAyC;IACzC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB;sBAEb,gBAAgB,aAAa,gBAAgB;;;;EA8BlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,kBAAkB,SAAqB,QASjK;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,oBAAoB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,QAYxI;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,gBAAgB,CA6B9I;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,wBAAwB,EAAE,MAAM,EAChC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,oBAAoB,SAAY,EAChC,SAAS,SAAI,EACb,YAAY,UAAQ,EACpB,sBAAsB,SAA0B,oBAUjD"}
|
|
@@ -59,8 +59,7 @@ exports.toBeVisuallySimilar = toBeVisuallySimilar;
|
|
|
59
59
|
* It will create a file for the passed screenshot object.
|
|
60
60
|
* The path of the new file will be calculated using the parameters
|
|
61
61
|
* Ex: ./dist-screenshots\OWBooking\windows_chrome_91\fare-page-after-click-on-continue-0.png
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png
|
|
64
63
|
* @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()
|
|
65
64
|
* @param scenarioName E2e Scenario class name
|
|
66
65
|
* @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`
|
|
@@ -82,7 +81,6 @@ exports.saveScreenshot = saveScreenshot;
|
|
|
82
81
|
/**
|
|
83
82
|
* Write the 3 images (base/new/diff) on the reports folder
|
|
84
83
|
* The path inside the reports forlder will be calculated using the parameters
|
|
85
|
-
*
|
|
86
84
|
* @param pathToScenarioReport Path where the scenario report is saved inside reports folder
|
|
87
85
|
* @param screenshotsDirName Name of the directory which will contain the 3 images
|
|
88
86
|
* @param diff diff image
|
|
@@ -104,7 +102,6 @@ function writeScreenshotsDiff(pathToScenarioReport, screenshotsDirName, diff, ba
|
|
|
104
102
|
exports.writeScreenshotsDiff = writeScreenshotsDiff;
|
|
105
103
|
/**
|
|
106
104
|
* Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario
|
|
107
|
-
*
|
|
108
105
|
* @param screenshot Actual captured screenshot object
|
|
109
106
|
* @param baseImagePath The path to the base screenshot
|
|
110
107
|
* @param threshold The diff between base screenshot and the current one should not be bigger than this value.
|
|
@@ -144,7 +141,6 @@ function compareScreenshot(screenshot, baseImagePath, threshold, pathToScenarioR
|
|
|
144
141
|
exports.compareScreenshot = compareScreenshot;
|
|
145
142
|
/**
|
|
146
143
|
* Helper function to perform a visual test operation
|
|
147
|
-
*
|
|
148
144
|
* @param screenshotObj Ex: for protractor browser.takeScreenshot()
|
|
149
145
|
* @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end
|
|
150
146
|
* @param device os followed by browser version - ex: `Windows 10 chrome 89`
|
|
@@ -1 +1 @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B,aAAqB,EACrB,wBAAgC,EAChC,MAAc,EACd,YAAoB,EACpB,oBAAgC,EAChC,SAAa,EACb,YAAoB,EACpB,sBAAgD;IAHhD,qCAAA,EAAA,gCAAgC;IAChC,0BAAA,EAAA,aAAa;IACb,6BAAA,EAAA,oBAAoB;IACpB,uCAAA,EAAA,gDAAgD;IAEhD,IAAI,YAAY,EAAE;QAChB,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC9E,OAAO,EAAC,YAAY,EAAE,IAAI,EAAC,CAAC;KAC7B;SAAM;QACL,IAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,YAAY,EAAE,MAAM,EAAE,UAAG,wBAAwB,SAAM,CAAC,CAAC;QACpH,IAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC1G,OAAO,gBAAgB,CAAC;KACzB;AACH,CAAC;AAlBD,sCAkBC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport {PNG} from 'pngjs';\nimport * as pixelmatch from 'pixelmatch';\n\nexport {\n prepareVisualTesting,\n toggleVisualTestingRender\n} from './utils';\n\n/** Error types returned by visual testing comparison */\nexport interface VisualTestMessage {\n /** Error message when base image and actual image have different sizes */\n imagesSize: string;\n /** Error message when base screensot not found */\n baseImgNotFound: string;\n /** Error message when the threshold is passed */\n diffMessage: string;\n /** The message in case of success */\n success: string;\n /** The message in case of generate mode run */\n generateMode: string;\n}\n\n/** Error messages in case of visual testing failure */\nexport const visualTestMessages: VisualTestMessage = {\n imagesSize: 'Image sizes do not match for:',\n diffMessage: 'Diff between images is greater than threshold for:',\n baseImgNotFound: 'Base screenshot file not found:',\n success: 'Visual test successful',\n generateMode: 'Run in generate screenshot mode'\n};\n\n/**\n * Object returned by a visual test operation\n */\nexport interface VisualTestResult {\n /** Error object when base image and actual image have different sizes; Contains the screenshot ffile name */\n imagesSize?: {screenshotName: string};\n /** Error object when base screensot not found. Contains the not found path as a string */\n baseScreenshotNotFound?: {baseScreenshotPath: string};\n /** Object containing the actual diff between images as percentage, the threshold and screenshot file name */\n diff?: {actualDiff: number; threshold: number; screenshotName: string};\n /** Run only generation of screenshots */\n generateMode?: boolean;\n}\n\n/**\n * Visual test matcher\n * Based on the VisualTestResult object return by compareScreenshots function, this matcher will compute the error messages\n */\nexport function toBeVisuallySimilar() {\n return {\n compare: (actual: VisualTestResult, _expected: VisualTestResult) => {\n if (actual.generateMode) {\n return {\n pass: true,\n message: visualTestMessages.generateMode\n };\n }\n if (actual.baseScreenshotNotFound) {\n return {\n pass: false,\n message: `${visualTestMessages.baseImgNotFound} ${actual.baseScreenshotNotFound.baseScreenshotPath}`};\n }\n if (actual.imagesSize) {\n return {\n pass: false,\n message: `${visualTestMessages.imagesSize} ${actual.imagesSize.screenshotName}`\n };\n }\n if (actual.diff && actual.diff.actualDiff > actual.diff.threshold) {\n return {\n pass: false,\n message: `${actual.diff.actualDiff} > ${actual.diff.threshold} : ${visualTestMessages.diffMessage} ${actual.diff.screenshotName}`\n };\n }\n return {\n pass: true,\n message: visualTestMessages.success\n };\n }\n };\n}\n\n/**\n * It will create a file for the passed screenshot object.\n * The path of the new file will be calculated using the parameters\n * Ex: ./dist-screenshots\\OWBooking\\windows_chrome_91\\fare-page-after-click-on-continue-0.png\n * distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png\n *\n * @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()\n * @param scenarioName E2e Scenario class name\n * @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param distScreenshotsDir Name of the directory to save the screenshots\n */\nexport function saveScreenshot(screenshot: string, scenarioName: string, device: string, filenameWithoutExtension: string, distScreenshotsDir = 'dist-screenshots') {\n const screenshotsDir = path.resolve(distScreenshotsDir, scenarioName, `${device.replace(/ +/g, '_')}`);\n if (!fs.existsSync(screenshotsDir)) {\n fs.mkdirSync(screenshotsDir, {recursive: true});\n }\n const fullFileName = `${filenameWithoutExtension}.png`;\n const stream = fs.createWriteStream(path.resolve(screenshotsDir, fullFileName));\n stream.write(Buffer.from(screenshot, 'base64'));\n stream.end();\n}\n\n/**\n * Write the 3 images (base/new/diff) on the reports folder\n * The path inside the reports forlder will be calculated using the parameters\n *\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder\n * @param screenshotsDirName Name of the directory which will contain the 3 images\n * @param diff diff image\n * @param baseImage the base image\n * @param currentImg the actual taken screenshot image\n */\nexport function writeScreenshotsDiff(pathToScenarioReport: string, screenshotsDirName: string, diff: PNG, baseImage: PNG, currentImg: PNG) {\n const destScreenshotsDiffDir = path.join(pathToScenarioReport, 'screenshots-diff', screenshotsDirName);\n if (!fs.existsSync(destScreenshotsDiffDir)) {\n fs.mkdirSync(destScreenshotsDiffDir, { recursive: true });\n }\n\n const diffPath = path.resolve(destScreenshotsDiffDir, 'diff.png');\n const oldPath = path.resolve(destScreenshotsDiffDir, 'old.png');\n const newPath = path.resolve(destScreenshotsDiffDir, 'new.png');\n fs.writeFileSync(diffPath, PNG.sync.write(diff));\n fs.writeFileSync(oldPath, PNG.sync.write(baseImage));\n fs.writeFileSync(newPath, PNG.sync.write(currentImg));\n}\n\n/**\n * Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario\n *\n * @param screenshot Actual captured screenshot object\n * @param baseImagePath The path to the base screenshot\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder. Used to compute the path to write diff images in case there is a diff at comparison\n * @returns An object of visual test result type\n */\nexport function compareScreenshot(screenshot: string, baseImagePath: string, threshold: number, pathToScenarioReport: string): VisualTestResult {\n const baseImageExists = fs.existsSync(baseImagePath);\n if (!baseImageExists) {\n return {baseScreenshotNotFound: {baseScreenshotPath: baseImagePath}};\n }\n else {\n const baseImage = PNG.sync.read(fs.readFileSync(baseImagePath));\n const {width, height} = baseImage;\n const diff = new PNG({width, height});\n\n const screenshotBuffer = Buffer.from(screenshot, 'base64');\n const currentImg = PNG.sync.read(screenshotBuffer);\n const diffDirName = path.basename(baseImagePath, '.png');\n let result;\n try {\n result = pixelmatch(baseImage.data, currentImg.data, diff.data, width, height, {threshold: 0.1});\n } catch (err: any) {\n if (err.toString().indexOf('Image sizes do not match.') === -1) {\n throw err;\n }\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n return {imagesSize: {screenshotName: diffDirName}};\n }\n const pr = Math.round(100 * 100 * result / (width * height)) / 100;\n if (pr > threshold) {\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n }\n return {diff: {actualDiff: pr, threshold, screenshotName: diffDirName}};\n }\n}\n\n/**\n * Helper function to perform a visual test operation\n *\n * @param screenshotObj Ex: for protractor browser.takeScreenshot()\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param device os followed by browser version - ex: `Windows 10 chrome 89`\n * @param scenarioName E2e Scenario class name\n * @param pathToScenarioReport Path used in compare mode for saving the base,new,diff images in reports in case there is a diff\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * If the diff is bigger, 3 png files will be created: base screenshot, new screenshot and diff image\n * @param generateMode If true it will generate the screenshot file without screenshots comparison\n * @param baseScreenshotsDirPath The folder path to search base screenshots; used only in compare mode\n */\nexport function o3rVisualTest(\n screenshotObj: string,\n filenameWithoutExtension: string,\n device: string,\n scenarioName: string,\n pathToScenarioReport = 'reports',\n threshold = 0,\n generateMode = false,\n baseScreenshotsDirPath = 'dist-screenshots-base'\n) {\n if (generateMode) {\n saveScreenshot(screenshotObj, scenarioName, device, filenameWithoutExtension);\n return {generateMode: true};\n } else {\n const baseImagePath = path.resolve(baseScreenshotsDirPath, scenarioName, device, `${filenameWithoutExtension}.png`);\n const visualTestResult = compareScreenshot(screenshotObj, baseImagePath, threshold, pathToScenarioReport);\n return visualTestResult;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"visual-test.js","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":";;;AAAA,4BAA8B;AAC9B,gCAAkC;AAClC,+BAA0B;AAC1B,uCAAyC;AAEzC,iCAGiB;AAFf,6GAAA,oBAAoB,OAAA;AACpB,kHAAA,yBAAyB,OAAA;AAiB3B,uDAAuD;AAC1C,QAAA,kBAAkB,GAAsB;IACnD,UAAU,EAAE,+BAA+B;IAC3C,WAAW,EAAE,oDAAoD;IACjE,eAAe,EAAE,iCAAiC;IAClD,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,iCAAiC;CAChD,CAAC;AAgBF;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,UAAC,MAAwB,EAAE,SAA2B;YAC7D,IAAI,MAAM,CAAC,YAAY,EAAE;gBACvB,OAAO;oBACL,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,0BAAkB,CAAC,YAAY;iBACzC,CAAC;aACH;YACD,IAAI,MAAM,CAAC,sBAAsB,EAAE;gBACjC,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,UAAG,0BAAkB,CAAC,eAAe,cAAI,MAAM,CAAC,sBAAsB,CAAC,kBAAkB,CAAE;iBAAC,CAAC;aACzG;YACD,IAAI,MAAM,CAAC,UAAU,EAAE;gBACrB,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,UAAG,0BAAkB,CAAC,UAAU,cAAI,MAAM,CAAC,UAAU,CAAC,cAAc,CAAE;iBAChF,CAAC;aACH;YACD,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE;gBACjE,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,U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CAAC;AA7BD,8CA6BC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,aAAqB,EACrB,wBAAgC,EAChC,MAAc,EACd,YAAoB,EACpB,oBAAgC,EAChC,SAAa,EACb,YAAoB,EACpB,sBAAgD;IAHhD,qCAAA,EAAA,gCAAgC;IAChC,0BAAA,EAAA,aAAa;IACb,6BAAA,EAAA,oBAAoB;IACpB,uCAAA,EAAA,gDAAgD;IAEhD,IAAI,YAAY,EAAE;QAChB,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC9E,OAAO,EAAC,YAAY,EAAE,IAAI,EAAC,CAAC;KAC7B;SAAM;QACL,IAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,YAAY,EAAE,MAAM,EAAE,UAAG,wBAAwB,SAAM,CAAC,CAAC;QACpH,IAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC1G,OAAO,gBAAgB,CAAC;KACzB;AACH,CAAC;AAlBD,sCAkBC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport {PNG} from 'pngjs';\nimport * as pixelmatch from 'pixelmatch';\n\nexport {\n prepareVisualTesting,\n toggleVisualTestingRender\n} from './utils';\n\n/** Error types returned by visual testing comparison */\nexport interface VisualTestMessage {\n /** Error message when base image and actual image have different sizes */\n imagesSize: string;\n /** Error message when base screensot not found */\n baseImgNotFound: string;\n /** Error message when the threshold is passed */\n diffMessage: string;\n /** The message in case of success */\n success: string;\n /** The message in case of generate mode run */\n generateMode: string;\n}\n\n/** Error messages in case of visual testing failure */\nexport const visualTestMessages: VisualTestMessage = {\n imagesSize: 'Image sizes do not match for:',\n diffMessage: 'Diff between images is greater than threshold for:',\n baseImgNotFound: 'Base screenshot file not found:',\n success: 'Visual test successful',\n generateMode: 'Run in generate screenshot mode'\n};\n\n/**\n * Object returned by a visual test operation\n */\nexport interface VisualTestResult {\n /** Error object when base image and actual image have different sizes; Contains the screenshot ffile name */\n imagesSize?: {screenshotName: string};\n /** Error object when base screensot not found. Contains the not found path as a string */\n baseScreenshotNotFound?: {baseScreenshotPath: string};\n /** Object containing the actual diff between images as percentage, the threshold and screenshot file name */\n diff?: {actualDiff: number; threshold: number; screenshotName: string};\n /** Run only generation of screenshots */\n generateMode?: boolean;\n}\n\n/**\n * Visual test matcher\n * Based on the VisualTestResult object return by compareScreenshots function, this matcher will compute the error messages\n */\nexport function toBeVisuallySimilar() {\n return {\n compare: (actual: VisualTestResult, _expected: VisualTestResult) => {\n if (actual.generateMode) {\n return {\n pass: true,\n message: visualTestMessages.generateMode\n };\n }\n if (actual.baseScreenshotNotFound) {\n return {\n pass: false,\n message: `${visualTestMessages.baseImgNotFound} ${actual.baseScreenshotNotFound.baseScreenshotPath}`};\n }\n if (actual.imagesSize) {\n return {\n pass: false,\n message: `${visualTestMessages.imagesSize} ${actual.imagesSize.screenshotName}`\n };\n }\n if (actual.diff && actual.diff.actualDiff > actual.diff.threshold) {\n return {\n pass: false,\n message: `${actual.diff.actualDiff} > ${actual.diff.threshold} : ${visualTestMessages.diffMessage} ${actual.diff.screenshotName}`\n };\n }\n return {\n pass: true,\n message: visualTestMessages.success\n };\n }\n };\n}\n\n/**\n * It will create a file for the passed screenshot object.\n * The path of the new file will be calculated using the parameters\n * Ex: ./dist-screenshots\\OWBooking\\windows_chrome_91\\fare-page-after-click-on-continue-0.png\n * distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png\n * @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()\n * @param scenarioName E2e Scenario class name\n * @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param distScreenshotsDir Name of the directory to save the screenshots\n */\nexport function saveScreenshot(screenshot: string, scenarioName: string, device: string, filenameWithoutExtension: string, distScreenshotsDir = 'dist-screenshots') {\n const screenshotsDir = path.resolve(distScreenshotsDir, scenarioName, `${device.replace(/ +/g, '_')}`);\n if (!fs.existsSync(screenshotsDir)) {\n fs.mkdirSync(screenshotsDir, {recursive: true});\n }\n const fullFileName = `${filenameWithoutExtension}.png`;\n const stream = fs.createWriteStream(path.resolve(screenshotsDir, fullFileName));\n stream.write(Buffer.from(screenshot, 'base64'));\n stream.end();\n}\n\n/**\n * Write the 3 images (base/new/diff) on the reports folder\n * The path inside the reports forlder will be calculated using the parameters\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder\n * @param screenshotsDirName Name of the directory which will contain the 3 images\n * @param diff diff image\n * @param baseImage the base image\n * @param currentImg the actual taken screenshot image\n */\nexport function writeScreenshotsDiff(pathToScenarioReport: string, screenshotsDirName: string, diff: PNG, baseImage: PNG, currentImg: PNG) {\n const destScreenshotsDiffDir = path.join(pathToScenarioReport, 'screenshots-diff', screenshotsDirName);\n if (!fs.existsSync(destScreenshotsDiffDir)) {\n fs.mkdirSync(destScreenshotsDiffDir, { recursive: true });\n }\n\n const diffPath = path.resolve(destScreenshotsDiffDir, 'diff.png');\n const oldPath = path.resolve(destScreenshotsDiffDir, 'old.png');\n const newPath = path.resolve(destScreenshotsDiffDir, 'new.png');\n fs.writeFileSync(diffPath, PNG.sync.write(diff));\n fs.writeFileSync(oldPath, PNG.sync.write(baseImage));\n fs.writeFileSync(newPath, PNG.sync.write(currentImg));\n}\n\n/**\n * Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario\n * @param screenshot Actual captured screenshot object\n * @param baseImagePath The path to the base screenshot\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder. Used to compute the path to write diff images in case there is a diff at comparison\n * @returns An object of visual test result type\n */\nexport function compareScreenshot(screenshot: string, baseImagePath: string, threshold: number, pathToScenarioReport: string): VisualTestResult {\n const baseImageExists = fs.existsSync(baseImagePath);\n if (!baseImageExists) {\n return {baseScreenshotNotFound: {baseScreenshotPath: baseImagePath}};\n }\n else {\n const baseImage = PNG.sync.read(fs.readFileSync(baseImagePath));\n const {width, height} = baseImage;\n const diff = new PNG({width, height});\n\n const screenshotBuffer = Buffer.from(screenshot, 'base64');\n const currentImg = PNG.sync.read(screenshotBuffer);\n const diffDirName = path.basename(baseImagePath, '.png');\n let result;\n try {\n result = pixelmatch(baseImage.data, currentImg.data, diff.data, width, height, {threshold: 0.1});\n } catch (err: any) {\n if (err.toString().indexOf('Image sizes do not match.') === -1) {\n throw err;\n }\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n return {imagesSize: {screenshotName: diffDirName}};\n }\n const pr = Math.round(100 * 100 * result / (width * height)) / 100;\n if (pr > threshold) {\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n }\n return {diff: {actualDiff: pr, threshold, screenshotName: diffDirName}};\n }\n}\n\n/**\n * Helper function to perform a visual test operation\n * @param screenshotObj Ex: for protractor browser.takeScreenshot()\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param device os followed by browser version - ex: `Windows 10 chrome 89`\n * @param scenarioName E2e Scenario class name\n * @param pathToScenarioReport Path used in compare mode for saving the base,new,diff images in reports in case there is a diff\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * If the diff is bigger, 3 png files will be created: base screenshot, new screenshot and diff image\n * @param generateMode If true it will generate the screenshot file without screenshots comparison\n * @param baseScreenshotsDirPath The folder path to search base screenshots; used only in compare mode\n */\nexport function o3rVisualTest(\n screenshotObj: string,\n filenameWithoutExtension: string,\n device: string,\n scenarioName: string,\n pathToScenarioReport = 'reports',\n threshold = 0,\n generateMode = false,\n baseScreenshotsDirPath = 'dist-screenshots-base'\n) {\n if (generateMode) {\n saveScreenshot(screenshotObj, scenarioName, device, filenameWithoutExtension);\n return {generateMode: true};\n } else {\n const baseImagePath = path.resolve(baseScreenshotsDirPath, scenarioName, device, `${filenameWithoutExtension}.png`);\n const visualTestResult = compareScreenshot(screenshotObj, baseImagePath, threshold, pathToScenarioReport);\n return visualTestResult;\n }\n}\n"]}
|