@o3r/testing 11.6.0-prerelease.4 → 11.6.0-prerelease.40

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.
Files changed (239) hide show
  1. package/core/angular/angular-materials/autocomplete-material.d.ts +0 -1
  2. package/core/angular/angular-materials/autocomplete-material.d.ts.map +1 -1
  3. package/core/angular/angular-materials/autocomplete-material.js.map +1 -1
  4. package/core/angular/angular-materials/select-material.d.ts +0 -1
  5. package/core/angular/angular-materials/select-material.d.ts.map +1 -1
  6. package/core/angular/angular-materials/select-material.js +4 -3
  7. package/core/angular/angular-materials/select-material.js.map +1 -1
  8. package/core/angular/angular-materials/slider-material.d.ts.map +1 -1
  9. package/core/angular/angular-materials/slider-material.js.map +1 -1
  10. package/core/angular/component-fixture.d.ts.map +1 -1
  11. package/core/angular/component-fixture.js +3 -10
  12. package/core/angular/component-fixture.js.map +1 -1
  13. package/core/angular/element.d.ts.map +1 -1
  14. package/core/angular/element.js +2 -2
  15. package/core/angular/element.js.map +1 -1
  16. package/core/angular/elements/checkbox-element.d.ts.map +1 -1
  17. package/core/angular/elements/checkbox-element.js.map +1 -1
  18. package/core/angular/elements/radio-element.d.ts.map +1 -1
  19. package/core/angular/elements/radio-element.js.map +1 -1
  20. package/core/angular/elements/select-element.d.ts +0 -1
  21. package/core/angular/elements/select-element.d.ts.map +1 -1
  22. package/core/angular/elements/select-element.js +2 -2
  23. package/core/angular/elements/select-element.js.map +1 -1
  24. package/core/angular/elements/slider-element.d.ts +2 -1
  25. package/core/angular/elements/slider-element.d.ts.map +1 -1
  26. package/core/angular/elements/slider-element.js +2 -1
  27. package/core/angular/elements/slider-element.js.map +1 -1
  28. package/core/angular/group.d.ts.map +1 -1
  29. package/core/angular/group.js.map +1 -1
  30. package/core/angular/groups/radio-group.d.ts.map +1 -1
  31. package/core/angular/groups/radio-group.js.map +1 -1
  32. package/core/angular/index.d.ts +3 -2
  33. package/core/angular/index.d.ts.map +1 -1
  34. package/core/angular/index.js +2 -2
  35. package/core/angular/index.js.map +1 -1
  36. package/core/angular/page-fixture.d.ts.map +1 -1
  37. package/core/angular/page-fixture.js.map +1 -1
  38. package/core/angular-materials/autocomplete-material.d.ts.map +1 -1
  39. package/core/angular-materials/autocomplete-material.js.map +1 -1
  40. package/core/angular-materials/select-material.d.ts.map +1 -1
  41. package/core/angular-materials/select-material.js.map +1 -1
  42. package/core/angular-materials/slider-material.d.ts.map +1 -1
  43. package/core/angular-materials/slider-material.js.map +1 -1
  44. package/core/component-fixture.d.ts +18 -36
  45. package/core/component-fixture.d.ts.map +1 -1
  46. package/core/component-fixture.js +18 -36
  47. package/core/component-fixture.js.map +1 -1
  48. package/core/element.d.ts.map +1 -1
  49. package/core/element.js.map +1 -1
  50. package/core/elements/checkbox-element.d.ts.map +1 -1
  51. package/core/elements/checkbox-element.js.map +1 -1
  52. package/core/elements/radio-element.d.ts.map +1 -1
  53. package/core/elements/radio-element.js.map +1 -1
  54. package/core/elements/select-element.d.ts.map +1 -1
  55. package/core/elements/select-element.js.map +1 -1
  56. package/core/elements/slider-element.d.ts.map +1 -1
  57. package/core/elements/slider-element.js.map +1 -1
  58. package/core/group.d.ts.map +1 -1
  59. package/core/group.js.map +1 -1
  60. package/core/groups/radio-group.d.ts.map +1 -1
  61. package/core/groups/radio-group.js.map +1 -1
  62. package/core/helpers.d.ts +1 -1
  63. package/core/helpers.d.ts.map +1 -1
  64. package/core/helpers.js.map +1 -1
  65. package/core/index.d.ts +2 -2
  66. package/core/index.d.ts.map +1 -1
  67. package/core/index.js +2 -2
  68. package/core/index.js.map +1 -1
  69. package/core/page-fixture.d.ts.map +1 -1
  70. package/core/page-fixture.js.map +1 -1
  71. package/core/playwright/angular-materials/autocomplete-material.d.ts +0 -1
  72. package/core/playwright/angular-materials/autocomplete-material.d.ts.map +1 -1
  73. package/core/playwright/angular-materials/autocomplete-material.js +1 -1
  74. package/core/playwright/angular-materials/autocomplete-material.js.map +1 -1
  75. package/core/playwright/angular-materials/select-material.d.ts +0 -1
  76. package/core/playwright/angular-materials/select-material.d.ts.map +1 -1
  77. package/core/playwright/angular-materials/select-material.js +3 -3
  78. package/core/playwright/angular-materials/select-material.js.map +1 -1
  79. package/core/playwright/angular-materials/slider-material.d.ts.map +1 -1
  80. package/core/playwright/angular-materials/slider-material.js.map +1 -1
  81. package/core/playwright/component-fixture.d.ts.map +1 -1
  82. package/core/playwright/component-fixture.js +2 -10
  83. package/core/playwright/component-fixture.js.map +1 -1
  84. package/core/playwright/element.d.ts.map +1 -1
  85. package/core/playwright/element.js +11 -10
  86. package/core/playwright/element.js.map +1 -1
  87. package/core/playwright/elements/checkbox-element.d.ts +2 -1
  88. package/core/playwright/elements/checkbox-element.d.ts.map +1 -1
  89. package/core/playwright/elements/checkbox-element.js +4 -1
  90. package/core/playwright/elements/checkbox-element.js.map +1 -1
  91. package/core/playwright/elements/index.d.ts +2 -2
  92. package/core/playwright/elements/index.d.ts.map +1 -1
  93. package/core/playwright/elements/index.js +2 -2
  94. package/core/playwright/elements/index.js.map +1 -1
  95. package/core/playwright/elements/radio-element.d.ts.map +1 -1
  96. package/core/playwright/elements/radio-element.js +1 -0
  97. package/core/playwright/elements/radio-element.js.map +1 -1
  98. package/core/playwright/elements/select-element.d.ts.map +1 -1
  99. package/core/playwright/elements/select-element.js.map +1 -1
  100. package/core/playwright/elements/slider-element.d.ts.map +1 -1
  101. package/core/playwright/elements/slider-element.js.map +1 -1
  102. package/core/playwright/group.d.ts.map +1 -1
  103. package/core/playwright/group.js.map +1 -1
  104. package/core/playwright/groups/radio-group.d.ts.map +1 -1
  105. package/core/playwright/groups/radio-group.js.map +1 -1
  106. package/core/playwright/index.d.ts +3 -2
  107. package/core/playwright/index.d.ts.map +1 -1
  108. package/core/playwright/index.js +2 -2
  109. package/core/playwright/index.js.map +1 -1
  110. package/core/playwright/page-fixture.d.ts.map +1 -1
  111. package/core/playwright/page-fixture.js.map +1 -1
  112. package/core/protractor/angular-materials/autocomplete-material.d.ts +0 -1
  113. package/core/protractor/angular-materials/autocomplete-material.d.ts.map +1 -1
  114. package/core/protractor/angular-materials/autocomplete-material.js.map +1 -1
  115. package/core/protractor/angular-materials/select-material.d.ts +0 -1
  116. package/core/protractor/angular-materials/select-material.d.ts.map +1 -1
  117. package/core/protractor/angular-materials/select-material.js +7 -6
  118. package/core/protractor/angular-materials/select-material.js.map +1 -1
  119. package/core/protractor/component-fixture.d.ts.map +1 -1
  120. package/core/protractor/component-fixture.js +6 -11
  121. package/core/protractor/component-fixture.js.map +1 -1
  122. package/core/protractor/element.d.ts.map +1 -1
  123. package/core/protractor/element.js +6 -4
  124. package/core/protractor/element.js.map +1 -1
  125. package/core/protractor/elements/checkbox-element.d.ts.map +1 -1
  126. package/core/protractor/elements/checkbox-element.js.map +1 -1
  127. package/core/protractor/elements/index.d.ts +1 -1
  128. package/core/protractor/elements/index.d.ts.map +1 -1
  129. package/core/protractor/elements/index.js +1 -1
  130. package/core/protractor/elements/index.js.map +1 -1
  131. package/core/protractor/elements/radio-element.d.ts.map +1 -1
  132. package/core/protractor/elements/radio-element.js +1 -0
  133. package/core/protractor/elements/radio-element.js.map +1 -1
  134. package/core/protractor/elements/select-element.d.ts +0 -1
  135. package/core/protractor/elements/select-element.d.ts.map +1 -1
  136. package/core/protractor/elements/select-element.js.map +1 -1
  137. package/core/protractor/group.d.ts.map +1 -1
  138. package/core/protractor/group.js.map +1 -1
  139. package/core/protractor/groups/radio-group.d.ts.map +1 -1
  140. package/core/protractor/groups/radio-group.js +1 -0
  141. package/core/protractor/groups/radio-group.js.map +1 -1
  142. package/core/protractor/index.d.ts +3 -2
  143. package/core/protractor/index.d.ts.map +1 -1
  144. package/core/protractor/index.js +2 -2
  145. package/core/protractor/index.js.map +1 -1
  146. package/core/protractor/page-fixture.d.ts.map +1 -1
  147. package/core/protractor/page-fixture.js.map +1 -1
  148. package/core/protractor/utils.d.ts.map +1 -1
  149. package/core/protractor/utils.js.map +1 -1
  150. package/esm/utils.d.ts +19 -0
  151. package/esm/utils.d.ts.map +1 -0
  152. package/esm/utils.js +47 -0
  153. package/esm/utils.js.map +1 -0
  154. package/esm/visual-test/utils.d.ts +2 -2
  155. package/esm/visual-test/utils.js +3 -3
  156. package/esm/visual-test/utils.js.map +1 -1
  157. package/kassette/update-dates-in-mocks.d.ts.map +1 -1
  158. package/kassette/update-dates-in-mocks.js +3 -3
  159. package/kassette/update-dates-in-mocks.js.map +1 -1
  160. package/localization/localization-mock.d.ts.map +1 -1
  161. package/localization/localization-mock.js.map +1 -1
  162. package/mocks/mock-component-generator.d.ts +1 -1
  163. package/mocks/mock-component-generator.d.ts.map +1 -1
  164. package/mocks/mock-component-generator.js +15 -14
  165. package/mocks/mock-component-generator.js.map +1 -1
  166. package/package.json +36 -31
  167. package/schematics/add-functions-to-fixture/helpers.d.ts +0 -2
  168. package/schematics/add-functions-to-fixture/helpers.d.ts.map +1 -1
  169. package/schematics/add-functions-to-fixture/helpers.js +2 -4
  170. package/schematics/add-functions-to-fixture/helpers.js.map +1 -1
  171. package/schematics/add-functions-to-fixture/index.d.ts.map +1 -1
  172. package/schematics/add-functions-to-fixture/index.js +6 -6
  173. package/schematics/add-functions-to-fixture/index.js.map +1 -1
  174. package/schematics/add-functions-to-fixture/models.d.ts +18 -2
  175. package/schematics/add-functions-to-fixture/models.d.ts.map +1 -1
  176. package/schematics/add-functions-to-fixture/models.js.map +1 -1
  177. package/schematics/add-functions-to-fixture/schema.d.ts.map +1 -1
  178. package/schematics/fixture-to-component/index.d.ts.map +1 -1
  179. package/schematics/fixture-to-component/index.js +1 -1
  180. package/schematics/fixture-to-component/index.js.map +1 -1
  181. package/schematics/fixture-to-component/schema.d.ts.map +1 -1
  182. package/schematics/ng-add/fixture/index.d.ts.map +1 -1
  183. package/schematics/ng-add/fixture/index.js +4 -5
  184. package/schematics/ng-add/fixture/index.js.map +1 -1
  185. package/schematics/ng-add/index.d.ts.map +1 -1
  186. package/schematics/ng-add/index.js +16 -23
  187. package/schematics/ng-add/index.js.map +1 -1
  188. package/schematics/ng-add/playwright/index.d.ts.map +1 -1
  189. package/schematics/ng-add/playwright/index.js +5 -5
  190. package/schematics/ng-add/playwright/index.js.map +1 -1
  191. package/schematics/ng-add/schema.d.ts.map +1 -1
  192. package/schematics/ng-update/v9-0/index.d.ts.map +1 -1
  193. package/schematics/ng-update/v9-0/index.js +1 -1
  194. package/schematics/ng-update/v9-0/index.js.map +1 -1
  195. package/schematics/ng-update/v9-0/localization-imports/localization-imports-map.d.ts +16 -2
  196. package/schematics/ng-update/v9-0/localization-imports/localization-imports-map.d.ts.map +1 -1
  197. package/schematics/ng-update/v9-0/localization-imports/localization-imports-map.js.map +1 -1
  198. package/schematics/ng-update/v9-0/localization-imports/localization-imports.d.ts.map +1 -1
  199. package/schematics/ng-update/v9-0/localization-imports/localization-imports.js +1 -2
  200. package/schematics/ng-update/v9-0/localization-imports/localization-imports.js.map +1 -1
  201. package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.d.ts.map +1 -1
  202. package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.js +13 -13
  203. package/schematics/ng-update/v9-0/throw-on-undefined/throw-on-undefined.js.map +1 -1
  204. package/schematics/playwright/sanity/index.d.ts.map +1 -1
  205. package/schematics/playwright/sanity/index.js.map +1 -1
  206. package/schematics/playwright/sanity/schema.d.ts.map +1 -1
  207. package/schematics/playwright/scenario/index.d.ts.map +1 -1
  208. package/schematics/playwright/scenario/index.js.map +1 -1
  209. package/schematics/playwright/scenario/schema.d.ts.map +1 -1
  210. package/store/testable-select.d.ts +1 -1
  211. package/store/testable-select.d.ts.map +1 -1
  212. package/store/testable-select.js +3 -2
  213. package/store/testable-select.js.map +1 -1
  214. package/store/typings.d.ts.map +1 -1
  215. package/store/typings.js.map +1 -1
  216. package/tools/index.d.ts +1 -1
  217. package/tools/index.d.ts.map +1 -1
  218. package/tools/index.js +1 -1
  219. package/tools/index.js.map +1 -1
  220. package/tools/path-replacement/path-replacement.d.ts.map +1 -1
  221. package/tools/path-replacement/path-replacement.js +6 -7
  222. package/tools/path-replacement/path-replacement.js.map +1 -1
  223. package/tools/protractor/fetch-manager/_fetch-manager.d.ts.map +1 -0
  224. package/tools/protractor/fetch-manager/_fetch-manager.js +127 -0
  225. package/tools/protractor/fetch-manager/_fetch-manager.js.map +1 -0
  226. package/tools/protractor/fetch-manager/utils.d.ts.map +1 -1
  227. package/tools/protractor/fetch-manager/utils.js.map +1 -1
  228. package/tools/protractor/post-message-interceptor/_post-message-interceptor.d.ts.map +1 -0
  229. package/tools/protractor/post-message-interceptor/_post-message-interceptor.js +157 -0
  230. package/tools/protractor/post-message-interceptor/_post-message-interceptor.js.map +1 -0
  231. package/tools/protractor/post-message-interceptor/post-message-interceptor.d.ts.map +1 -1
  232. package/tools/protractor/post-message-interceptor/post-message-interceptor.js.map +1 -1
  233. package/visual-test/utils.d.ts +2 -2
  234. package/visual-test/utils.js +3 -3
  235. package/visual-test/utils.js.map +1 -1
  236. package/visual-test/visual-test.d.ts +2 -2
  237. package/visual-test/visual-test.d.ts.map +1 -1
  238. package/visual-test/visual-test.js +6 -6
  239. package/visual-test/visual-test.js.map +1 -1
@@ -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 (!baseImageExists) {
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().indexOf('Image sizes do not match.') === -1) {
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;IACjE,eAAe,EAAE,iCAAiC;IAClD,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,iCAAiC;CAChD,C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;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;AAxMD,4BAA8B;AAC9B,gCAAkC;AAClC,uCAAyC;AACzC,+BAEe;AAEf,iCAGiB;AAFf,6GAAA,oBAAoB,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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: Readonly<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} as const;\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"]}