@o3r/testing 11.6.0-prerelease.6 → 11.6.0-prerelease.8
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/core/angular/angular-materials/autocomplete-material.d.ts +0 -1
- package/core/angular/angular-materials/autocomplete-material.d.ts.map +1 -1
- package/core/angular/angular-materials/autocomplete-material.js.map +1 -1
- package/core/angular/angular-materials/select-material.d.ts +0 -1
- package/core/angular/angular-materials/select-material.d.ts.map +1 -1
- package/core/angular/angular-materials/select-material.js +4 -3
- package/core/angular/angular-materials/select-material.js.map +1 -1
- package/core/angular/angular-materials/slider-material.d.ts.map +1 -1
- package/core/angular/angular-materials/slider-material.js.map +1 -1
- package/core/angular/component-fixture.d.ts.map +1 -1
- package/core/angular/component-fixture.js +3 -10
- package/core/angular/component-fixture.js.map +1 -1
- package/core/angular/element.d.ts.map +1 -1
- package/core/angular/element.js +2 -2
- package/core/angular/element.js.map +1 -1
- package/core/angular/elements/checkbox-element.d.ts.map +1 -1
- package/core/angular/elements/checkbox-element.js.map +1 -1
- package/core/angular/elements/radio-element.d.ts.map +1 -1
- package/core/angular/elements/radio-element.js.map +1 -1
- package/core/angular/elements/select-element.d.ts +0 -1
- package/core/angular/elements/select-element.d.ts.map +1 -1
- package/core/angular/elements/select-element.js +2 -2
- package/core/angular/elements/select-element.js.map +1 -1
- package/core/angular/elements/slider-element.d.ts +2 -1
- package/core/angular/elements/slider-element.d.ts.map +1 -1
- package/core/angular/elements/slider-element.js +2 -1
- package/core/angular/elements/slider-element.js.map +1 -1
- package/core/angular/group.d.ts.map +1 -1
- package/core/angular/group.js.map +1 -1
- package/core/angular/groups/radio-group.d.ts.map +1 -1
- package/core/angular/groups/radio-group.js.map +1 -1
- package/core/angular/index.d.ts +3 -2
- package/core/angular/index.d.ts.map +1 -1
- package/core/angular/index.js +2 -2
- package/core/angular/index.js.map +1 -1
- package/core/angular/page-fixture.d.ts.map +1 -1
- package/core/angular/page-fixture.js.map +1 -1
- package/core/angular-materials/autocomplete-material.d.ts.map +1 -1
- package/core/angular-materials/autocomplete-material.js.map +1 -1
- package/core/angular-materials/select-material.d.ts.map +1 -1
- package/core/angular-materials/select-material.js.map +1 -1
- package/core/angular-materials/slider-material.d.ts.map +1 -1
- package/core/angular-materials/slider-material.js.map +1 -1
- package/core/component-fixture.d.ts +18 -36
- package/core/component-fixture.d.ts.map +1 -1
- package/core/component-fixture.js +18 -36
- package/core/component-fixture.js.map +1 -1
- package/core/element.d.ts.map +1 -1
- package/core/element.js.map +1 -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.map +1 -1
- package/core/elements/radio-element.js.map +1 -1
- package/core/elements/select-element.d.ts.map +1 -1
- package/core/elements/select-element.js.map +1 -1
- package/core/elements/slider-element.d.ts.map +1 -1
- package/core/elements/slider-element.js.map +1 -1
- package/core/group.d.ts.map +1 -1
- package/core/group.js.map +1 -1
- package/core/groups/radio-group.d.ts.map +1 -1
- package/core/groups/radio-group.js.map +1 -1
- package/core/helpers.d.ts +1 -1
- package/core/helpers.d.ts.map +1 -1
- package/core/helpers.js.map +1 -1
- package/core/index.d.ts +2 -2
- package/core/index.d.ts.map +1 -1
- package/core/index.js +2 -2
- package/core/index.js.map +1 -1
- package/core/page-fixture.d.ts.map +1 -1
- package/core/page-fixture.js.map +1 -1
- package/core/playwright/angular-materials/autocomplete-material.d.ts +0 -1
- package/core/playwright/angular-materials/autocomplete-material.d.ts.map +1 -1
- package/core/playwright/angular-materials/autocomplete-material.js +1 -1
- package/core/playwright/angular-materials/autocomplete-material.js.map +1 -1
- package/core/playwright/angular-materials/select-material.d.ts +0 -1
- package/core/playwright/angular-materials/select-material.d.ts.map +1 -1
- package/core/playwright/angular-materials/select-material.js +3 -3
- package/core/playwright/angular-materials/select-material.js.map +1 -1
- package/core/playwright/angular-materials/slider-material.d.ts.map +1 -1
- package/core/playwright/angular-materials/slider-material.js.map +1 -1
- package/core/playwright/component-fixture.d.ts.map +1 -1
- package/core/playwright/component-fixture.js +2 -10
- package/core/playwright/component-fixture.js.map +1 -1
- package/core/playwright/element.d.ts.map +1 -1
- package/core/playwright/element.js +11 -10
- package/core/playwright/element.js.map +1 -1
- package/core/playwright/elements/checkbox-element.d.ts +2 -1
- package/core/playwright/elements/checkbox-element.d.ts.map +1 -1
- package/core/playwright/elements/checkbox-element.js +4 -1
- package/core/playwright/elements/checkbox-element.js.map +1 -1
- package/core/playwright/elements/index.d.ts +2 -2
- package/core/playwright/elements/index.d.ts.map +1 -1
- package/core/playwright/elements/index.js +2 -2
- package/core/playwright/elements/index.js.map +1 -1
- package/core/playwright/elements/radio-element.d.ts.map +1 -1
- package/core/playwright/elements/radio-element.js +1 -0
- package/core/playwright/elements/radio-element.js.map +1 -1
- package/core/playwright/elements/select-element.d.ts.map +1 -1
- package/core/playwright/elements/select-element.js.map +1 -1
- package/core/playwright/elements/slider-element.d.ts.map +1 -1
- package/core/playwright/elements/slider-element.js.map +1 -1
- package/core/playwright/group.d.ts.map +1 -1
- package/core/playwright/group.js.map +1 -1
- package/core/playwright/groups/radio-group.d.ts.map +1 -1
- package/core/playwright/groups/radio-group.js.map +1 -1
- package/core/playwright/index.d.ts +3 -2
- package/core/playwright/index.d.ts.map +1 -1
- package/core/playwright/index.js +2 -2
- package/core/playwright/index.js.map +1 -1
- package/core/playwright/page-fixture.d.ts.map +1 -1
- package/core/playwright/page-fixture.js.map +1 -1
- package/core/protractor/angular-materials/autocomplete-material.d.ts +0 -1
- package/core/protractor/angular-materials/autocomplete-material.d.ts.map +1 -1
- package/core/protractor/angular-materials/autocomplete-material.js.map +1 -1
- package/core/protractor/angular-materials/select-material.d.ts +0 -1
- package/core/protractor/angular-materials/select-material.d.ts.map +1 -1
- package/core/protractor/angular-materials/select-material.js +7 -6
- package/core/protractor/angular-materials/select-material.js.map +1 -1
- package/core/protractor/component-fixture.d.ts.map +1 -1
- package/core/protractor/component-fixture.js +6 -11
- package/core/protractor/component-fixture.js.map +1 -1
- package/core/protractor/element.d.ts.map +1 -1
- package/core/protractor/element.js +6 -4
- package/core/protractor/element.js.map +1 -1
- package/core/protractor/elements/checkbox-element.d.ts.map +1 -1
- package/core/protractor/elements/checkbox-element.js.map +1 -1
- package/core/protractor/elements/index.d.ts +1 -1
- package/core/protractor/elements/index.d.ts.map +1 -1
- package/core/protractor/elements/index.js +1 -1
- package/core/protractor/elements/index.js.map +1 -1
- package/core/protractor/elements/radio-element.d.ts.map +1 -1
- package/core/protractor/elements/radio-element.js +1 -0
- package/core/protractor/elements/radio-element.js.map +1 -1
- package/core/protractor/elements/select-element.d.ts +0 -1
- package/core/protractor/elements/select-element.d.ts.map +1 -1
- package/core/protractor/elements/select-element.js.map +1 -1
- package/core/protractor/group.d.ts.map +1 -1
- package/core/protractor/group.js.map +1 -1
- package/core/protractor/groups/radio-group.d.ts.map +1 -1
- package/core/protractor/groups/radio-group.js +1 -0
- package/core/protractor/groups/radio-group.js.map +1 -1
- package/core/protractor/index.d.ts +3 -2
- package/core/protractor/index.d.ts.map +1 -1
- package/core/protractor/index.js +2 -2
- package/core/protractor/index.js.map +1 -1
- package/core/protractor/page-fixture.d.ts.map +1 -1
- package/core/protractor/page-fixture.js.map +1 -1
- package/core/protractor/utils.d.ts.map +1 -1
- package/core/protractor/utils.js.map +1 -1
- package/esm/visual-test/utils.d.ts +2 -2
- package/esm/visual-test/utils.js +3 -3
- package/esm/visual-test/utils.js.map +1 -1
- package/kassette/update-dates-in-mocks.d.ts.map +1 -1
- package/kassette/update-dates-in-mocks.js +3 -3
- package/kassette/update-dates-in-mocks.js.map +1 -1
- package/localization/localization-mock.d.ts.map +1 -1
- package/localization/localization-mock.js.map +1 -1
- package/mocks/mock-component-generator.d.ts +1 -1
- package/mocks/mock-component-generator.d.ts.map +1 -1
- package/mocks/mock-component-generator.js +15 -14
- package/mocks/mock-component-generator.js.map +1 -1
- package/package.json +23 -18
- package/schematics/add-functions-to-fixture/helpers.d.ts +0 -2
- package/schematics/add-functions-to-fixture/helpers.d.ts.map +1 -1
- package/schematics/add-functions-to-fixture/helpers.js +2 -4
- package/schematics/add-functions-to-fixture/helpers.js.map +1 -1
- package/schematics/add-functions-to-fixture/index.d.ts.map +1 -1
- package/schematics/add-functions-to-fixture/index.js +6 -6
- package/schematics/add-functions-to-fixture/index.js.map +1 -1
- package/schematics/add-functions-to-fixture/schema.d.ts.map +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.d.ts.map +1 -1
- package/schematics/ng-add/fixture/index.d.ts.map +1 -1
- package/schematics/ng-add/fixture/index.js +4 -5
- package/schematics/ng-add/fixture/index.js.map +1 -1
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +16 -23
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/playwright/index.d.ts.map +1 -1
- package/schematics/ng-add/playwright/index.js +5 -5
- package/schematics/ng-add/playwright/index.js.map +1 -1
- package/schematics/ng-add/schema.d.ts.map +1 -1
- package/schematics/ng-update/v9-0/index.d.ts.map +1 -1
- package/schematics/ng-update/v9-0/index.js +1 -1
- package/schematics/ng-update/v9-0/index.js.map +1 -1
- package/schematics/ng-update/v9-0/localization-imports/localization-imports-map.d.ts.map +1 -1
- package/schematics/ng-update/v9-0/localization-imports/localization-imports-map.js.map +1 -1
- package/schematics/ng-update/v9-0/localization-imports/localization-imports.d.ts.map +1 -1
- package/schematics/ng-update/v9-0/localization-imports/localization-imports.js +1 -2
- package/schematics/ng-update/v9-0/localization-imports/localization-imports.js.map +1 -1
- package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.d.ts.map +1 -1
- package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.js +13 -13
- package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.js.map +1 -1
- package/schematics/playwright/sanity/index.d.ts.map +1 -1
- package/schematics/playwright/sanity/index.js.map +1 -1
- package/schematics/playwright/sanity/schema.d.ts.map +1 -1
- package/schematics/playwright/scenario/index.d.ts.map +1 -1
- package/schematics/playwright/scenario/index.js.map +1 -1
- package/schematics/playwright/scenario/schema.d.ts.map +1 -1
- package/store/testable-select.d.ts +1 -1
- package/store/testable-select.d.ts.map +1 -1
- package/store/testable-select.js +3 -2
- package/store/testable-select.js.map +1 -1
- package/store/typings.d.ts.map +1 -1
- package/store/typings.js.map +1 -1
- package/tools/index.d.ts +1 -1
- package/tools/index.d.ts.map +1 -1
- package/tools/index.js +1 -1
- package/tools/index.js.map +1 -1
- package/tools/path-replacement/path-replacement.d.ts.map +1 -1
- package/tools/path-replacement/path-replacement.js +6 -7
- package/tools/path-replacement/path-replacement.js.map +1 -1
- package/tools/protractor/fetch-manager/utils.d.ts.map +1 -1
- package/tools/protractor/fetch-manager/utils.js.map +1 -1
- package/tools/protractor/post-message-interceptor/post-message-interceptor.d.ts.map +1 -1
- package/tools/protractor/post-message-interceptor/post-message-interceptor.js.map +1 -1
- package/visual-test/utils.d.ts +2 -2
- package/visual-test/utils.js +3 -3
- package/visual-test/utils.js.map +1 -1
- package/visual-test/visual-test.d.ts +1 -1
- package/visual-test/visual-test.d.ts.map +1 -1
- package/visual-test/visual-test.js +6 -6
- package/visual-test/visual-test.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/tools/protractor/fetch-manager/utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/tools/protractor/fetch-manager/utils.ts"],"names":[],"mappings":";;AAkBA,gDAOC;AAOD,4CAQC;AAMD,4CAEC;;AAhDD,4BAA8B;AAC9B,gCAAkC;AAClC,yCAEoB;AAEpB;;;;;;;;;;;GAWG;AACH,SAAsB,kBAAkB;;;;wBACtC,qBAAM,oBAAO,CAAC,cAAc,EAAE,EAAA;;oBAA9B,SAA8B,CAAC;yBAC3B,CAAC,oBAAO,CAAC,qBAAqB,EAA9B,wBAA8B;oBAChC,qBAAM,oBAAO,CAAC,kBAAkB,CAC9B,mFAAmF,CAAC,EAAA;;oBADtF,SACsF,CAAC;oBACvF,qBAAM,oBAAO,CAAC,cAAc,EAAE,EAAA;;oBAA9B,SAA8B,CAAC;;;;;;CAElC;AAED;;;;GAIG;AACH,SAAsB,gBAAgB;;;;;;oBAC9B,YAAY,GAAG,EAAE,CAAC,YAAY,CAClC,IAAI,CAAC,OAAO,CACV,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EACxF,mBAAmB,CAAC,EACtB,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;oBACxB,qBAAM,oBAAO,CAAC,aAAa,CAAC,YAAY,CAAC,EAAA;;oBAAzC,SAAyC,CAAC;oBAC1C,qBAAM,oBAAO,CAAC,aAAa,CAAC,2CAA2C,CAAC,EAAA;;oBAAxE,SAAwE,CAAC;;;;;CAC1E;AAED;;;GAGG;AACH,SAAsB,gBAAgB;;;;wBACpC,qBAAM,oBAAO,CAAC,aAAa,CAAC,2CAA2C,CAAC,EAAA;;oBAAxE,SAAwE,CAAC;;;;;CAC1E","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport {\n browser,\n} from 'protractor';\n\n/**\n * This function waits for all fetchs calls to be resolved and the page to be stable to resolve the promise.\n * It permits to easily run synchronous e2e tests on a flow that uses fetchs calls with protractor.\n * This is very useful in the case of Otter calls to backend because protractor synchronization manager do not care\n * about fetchs calls.\n *\n * This function needs the FetchManager to have been initialized and injected in the browser at the beginning of the\n * flow with `initFetchManager()`\n *\n * You can ignore the waiting of fetchs by setting `browser.ignoreSynchronization` to `true`\n * @deprecated Will be removed in v13, please use Playwright instead\n */\nexport async function waitForOtterStable() {\n await browser.waitForAngular();\n if (!browser.ignoreSynchronization) {\n await browser.executeAsyncScript(\n 'window.fetchManager.getInstance().waitForFetchs(arguments[arguments.length - 1]);');\n await browser.waitForAngular();\n }\n}\n\n/**\n * This function initiliaze the FetchManager. Set `window.fetch` variable with a custom behaviour in order to count the\n * fetch calls.\n * @deprecated Will be removed in v13, please use Playwright instead\n */\nexport async function initFetchManager() {\n const fetchManager = fs.readFileSync(\n path.resolve(\n process.cwd(), 'node_modules', '@o3r', 'testing', 'tools', 'protractor', 'fetch-manager',\n '_fetch-manager.js'),\n { encoding: 'utf8' });\n await browser.executeScript(fetchManager);\n await browser.executeScript('window.fetchManager.getInstance().init();');\n}\n\n/**\n * This function stops the FetchManager. Reset `window.fetch` variable with its native behaviour.\n * @deprecated Will be removed in v13, please use Playwright instead\n */\nexport async function stopFetchManager() {\n await browser.executeScript('window.fetchManager.getInstance().stop();');\n}\n"]}
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"post-message-interceptor.d.ts","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/post-message-interceptor.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,eAAe,EAChB,MAAM,QAAQ,CAAC;AAEhB;;;GAGG;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"}
|
|
@@ -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,
|
|
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,yCAEoB;AAMpB;;;GAGG;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,MAAM;yBACjB,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;oEAAyB,eAAqB,EAAE,OAAY;YAAnC,gCAAA,EAAA,qBAAqB;YAAE,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 {\n browser,\n} from 'protractor';\nimport {\n ConditionFn,\n PostMessageCall,\n} from './core';\n\n/**\n * Controls the postMessage interceptor\n * @deprecated Will be removed in v13, please use Playwright instead\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: 'utf8'\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,7 @@
|
|
|
2
2
|
* Prepare css rule to hide specific blocks
|
|
3
3
|
*
|
|
4
4
|
* Should be called only once during the visual test.
|
|
5
|
-
* @note
|
|
5
|
+
* @note this function is evaluated in the context of the page and should not use external variables
|
|
6
6
|
* @param ignoreClass
|
|
7
7
|
*/
|
|
8
8
|
export declare function prepareVisualTesting(ignoreClass?: string): void;
|
|
@@ -12,7 +12,7 @@ export declare function prepareVisualTesting(ignoreClass?: string): void;
|
|
|
12
12
|
export declare function isVisualTestingEnabled(): boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
|
|
15
|
-
* @note
|
|
15
|
+
* @note this function is evaluated in the context of the page and cannot use external code
|
|
16
16
|
* @param enabled
|
|
17
17
|
*/
|
|
18
18
|
export declare function toggleVisualTestingRender(enabled: boolean): void;
|
package/visual-test/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.toggleVisualTestingRender = toggleVisualTestingRender;
|
|
|
7
7
|
* Prepare css rule to hide specific blocks
|
|
8
8
|
*
|
|
9
9
|
* Should be called only once during the visual test.
|
|
10
|
-
* @note
|
|
10
|
+
* @note this function is evaluated in the context of the page and should not use external variables
|
|
11
11
|
* @param ignoreClass
|
|
12
12
|
*/
|
|
13
13
|
function prepareVisualTesting(ignoreClass) {
|
|
@@ -15,7 +15,7 @@ function prepareVisualTesting(ignoreClass) {
|
|
|
15
15
|
var visualTestingCss = document.createElement('style');
|
|
16
16
|
var visualTestingClass = 'visual-testing-render';
|
|
17
17
|
visualTestingCss.textContent = "\n .".concat(visualTestingClass, " .").concat(ignoreClass, " {position: relative;}\n\n .").concat(visualTestingClass, " .").concat(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 }");
|
|
18
|
-
document.head.
|
|
18
|
+
document.head.append(visualTestingCss);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Determine if the visual testing is enabled
|
|
@@ -26,7 +26,7 @@ function isVisualTestingEnabled() {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
|
|
29
|
-
* @note
|
|
29
|
+
* @note this function is evaluated in the context of the page and cannot use external code
|
|
30
30
|
* @param enabled
|
|
31
31
|
*/
|
|
32
32
|
function toggleVisualTestingRender(enabled) {
|
package/visual-test/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":";;AAOA,oDAkBC;AAKD,wDAGC;AAOD,8DAOC;AA/CD;;;;;;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,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/visual-test/utils.ts"],"names":[],"mappings":";;AAOA,oDAkBC;AAKD,wDAGC;AAOD,8DAOC;AA/CD;;;;;;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,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC;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;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,OAAgB;IACxD,IAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,IAAI,OAAO,EAAE,CAAC;QACZ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACrD,CAAC;AACH,CAAC","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.append(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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PNG } from 'pngjs';
|
|
2
|
-
export { prepareVisualTesting, toggleVisualTestingRender } from './utils';
|
|
2
|
+
export { prepareVisualTesting, toggleVisualTestingRender, } from './utils';
|
|
3
3
|
/** Error types returned by visual testing comparison */
|
|
4
4
|
export interface VisualTestMessage {
|
|
5
5
|
/** Error message when base image and actual image have different sizes */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-test.d.ts","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"visual-test.d.ts","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,GAAG,EACJ,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,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,EAAE,MAAM,CAAC;CACtB;AAED,uDAAuD;AACvD,eAAO,MAAM,kBAAkB,EAAE,iBAMhC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6GAA6G;IAC7G,UAAU,CAAC,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,0FAA0F;IAC1F,sBAAsB,CAAC,EAAE;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,6GAA6G;IAC7G,IAAI,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IACzE,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,CA4B9I;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"}
|
|
@@ -8,8 +8,8 @@ exports.compareScreenshot = compareScreenshot;
|
|
|
8
8
|
exports.o3rVisualTest = o3rVisualTest;
|
|
9
9
|
var fs = require("node:fs");
|
|
10
10
|
var path = require("node:path");
|
|
11
|
-
var pngjs_1 = require("pngjs");
|
|
12
11
|
var pixelmatch = require("pixelmatch");
|
|
12
|
+
var pngjs_1 = require("pngjs");
|
|
13
13
|
var utils_1 = require("./utils");
|
|
14
14
|
Object.defineProperty(exports, "prepareVisualTesting", { enumerable: true, get: function () { return utils_1.prepareVisualTesting; } });
|
|
15
15
|
Object.defineProperty(exports, "toggleVisualTestingRender", { enumerable: true, get: function () { return utils_1.toggleVisualTestingRender; } });
|
|
@@ -112,10 +112,7 @@ function writeScreenshotsDiff(pathToScenarioReport, screenshotsDirName, diff, ba
|
|
|
112
112
|
*/
|
|
113
113
|
function compareScreenshot(screenshot, baseImagePath, threshold, pathToScenarioReport) {
|
|
114
114
|
var baseImageExists = fs.existsSync(baseImagePath);
|
|
115
|
-
if (
|
|
116
|
-
return { baseScreenshotNotFound: { baseScreenshotPath: baseImagePath } };
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
115
|
+
if (baseImageExists) {
|
|
119
116
|
var baseImage = pngjs_1.PNG.sync.read(fs.readFileSync(baseImagePath));
|
|
120
117
|
var width = baseImage.width, height = baseImage.height;
|
|
121
118
|
var diff = new pngjs_1.PNG({ width: width, height: height });
|
|
@@ -127,7 +124,7 @@ function compareScreenshot(screenshot, baseImagePath, threshold, pathToScenarioR
|
|
|
127
124
|
result = pixelmatch(baseImage.data, currentImg.data, diff.data, width, height, { threshold: 0.1 });
|
|
128
125
|
}
|
|
129
126
|
catch (err) {
|
|
130
|
-
if (err.toString().
|
|
127
|
+
if (!err.toString().includes('Image sizes do not match.')) {
|
|
131
128
|
throw err;
|
|
132
129
|
}
|
|
133
130
|
writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);
|
|
@@ -139,6 +136,9 @@ function compareScreenshot(screenshot, baseImagePath, threshold, pathToScenarioR
|
|
|
139
136
|
}
|
|
140
137
|
return { diff: { actualDiff: pr, threshold: threshold, screenshotName: diffDirName } };
|
|
141
138
|
}
|
|
139
|
+
else {
|
|
140
|
+
return { baseScreenshotNotFound: { baseScreenshotPath: baseImagePath } };
|
|
141
|
+
}
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Helper function to perform a visual test operation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-test.js","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":";;;AAmDA,kDAgCC;AAaD,wCASC;AAWD,oDAYC;AAUD,8CA6BC;AAcD,sCAkBC;AAvMD,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;I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EAAE,CAAC;QACjB,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC9E,OAAO,EAAC,YAAY,EAAE,IAAI,EAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,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;IAC1B,CAAC;AACH,CAAC","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"]}
|
|
1
|
+
{"version":3,"file":"visual-test.js","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":";;;AAqDA,kDAgCC;AAaD,wCASC;AAWD,oDAYC;AAUD,8CA4BC;AAcD,sCAkBC;AA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BAAgC,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,CAAC;QACjB,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC9E,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,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;IAC1B,CAAC;AACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as pixelmatch from 'pixelmatch';\nimport {\n PNG,\n} from 'pngjs';\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 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().includes('Image sizes do not match.')) {\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 } else {\n return { baseScreenshotNotFound: { baseScreenshotPath: baseImagePath } };\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"]}
|