@wdio/image-comparison-core 1.1.4 → 1.2.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/base.interfaces.d.ts +7 -0
  3. package/dist/base.interfaces.d.ts.map +1 -1
  4. package/dist/clientSideScripts/injectWebviewOverlay.test.js +29 -0
  5. package/dist/clientSideScripts/scrollElementIntoView.d.ts.map +1 -1
  6. package/dist/clientSideScripts/scrollElementIntoView.js +4 -1
  7. package/dist/clientSideScripts/scrollElementIntoView.test.js +4 -2
  8. package/dist/commands/check.interfaces.d.ts +1 -1
  9. package/dist/commands/check.interfaces.d.ts.map +1 -1
  10. package/dist/commands/checkFullPageScreen.d.ts.map +1 -1
  11. package/dist/commands/checkFullPageScreen.js +7 -2
  12. package/dist/commands/checkWebElement.d.ts.map +1 -1
  13. package/dist/commands/checkWebElement.js +7 -2
  14. package/dist/commands/checkWebScreen.d.ts.map +1 -1
  15. package/dist/commands/checkWebScreen.js +10 -3
  16. package/dist/commands/checkWebScreen.test.js +43 -0
  17. package/dist/commands/fullPage.interfaces.d.ts +6 -0
  18. package/dist/commands/fullPage.interfaces.d.ts.map +1 -1
  19. package/dist/commands/save.interfaces.d.ts +3 -1
  20. package/dist/commands/save.interfaces.d.ts.map +1 -1
  21. package/dist/commands/saveElement.d.ts +1 -1
  22. package/dist/commands/saveElement.d.ts.map +1 -1
  23. package/dist/commands/saveElement.js +2 -2
  24. package/dist/commands/saveFullPageScreen.d.ts.map +1 -1
  25. package/dist/commands/saveFullPageScreen.js +23 -3
  26. package/dist/commands/saveWebElement.d.ts +1 -1
  27. package/dist/commands/saveWebElement.d.ts.map +1 -1
  28. package/dist/commands/saveWebElement.js +24 -2
  29. package/dist/commands/saveWebScreen.d.ts +1 -1
  30. package/dist/commands/saveWebScreen.d.ts.map +1 -1
  31. package/dist/commands/saveWebScreen.js +23 -3
  32. package/dist/helpers/afterScreenshot.interfaces.d.ts +2 -0
  33. package/dist/helpers/afterScreenshot.interfaces.d.ts.map +1 -1
  34. package/dist/helpers/options.d.ts.map +1 -1
  35. package/dist/helpers/options.interfaces.d.ts +10 -0
  36. package/dist/helpers/options.interfaces.d.ts.map +1 -1
  37. package/dist/helpers/options.js +1 -0
  38. package/dist/helpers/utils.d.ts +6 -0
  39. package/dist/helpers/utils.d.ts.map +1 -1
  40. package/dist/helpers/utils.interfaces.d.ts +3 -0
  41. package/dist/helpers/utils.interfaces.d.ts.map +1 -1
  42. package/dist/helpers/utils.js +95 -29
  43. package/dist/helpers/utils.test.js +121 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/methods/images.d.ts.map +1 -1
  47. package/dist/methods/images.interfaces.d.ts +4 -0
  48. package/dist/methods/images.interfaces.d.ts.map +1 -1
  49. package/dist/methods/images.js +4 -2
  50. package/dist/methods/rectangles.d.ts +33 -2
  51. package/dist/methods/rectangles.d.ts.map +1 -1
  52. package/dist/methods/rectangles.interfaces.d.ts +58 -0
  53. package/dist/methods/rectangles.interfaces.d.ts.map +1 -1
  54. package/dist/methods/rectangles.js +289 -15
  55. package/dist/methods/rectangles.test.js +558 -2
  56. package/dist/methods/takeElementScreenshots.js +19 -16
  57. package/dist/methods/takeElementScreenshots.test.js +22 -22
  58. package/package.json +3 -3
@@ -74,7 +74,7 @@ describe('takeElementScreenshot', () => {
74
74
  vi.clearAllMocks();
75
75
  });
76
76
  describe('BiDi screenshots', () => {
77
- it('should take BiDi screenshot from viewport when shouldUseBidi is true', async () => {
77
+ it('should take BiDi screenshot from document when shouldUseBidi is true', async () => {
78
78
  const result = await takeElementScreenshot(browserInstance, baseOptions, true);
79
79
  expect(result).toEqual({
80
80
  base64Image: 'bidi-screenshot-data',
@@ -83,37 +83,37 @@ describe('takeElementScreenshot', () => {
83
83
  expect(getElementRectMock).toHaveBeenCalledWith('test-element');
84
84
  expect(takeBase64BiDiScreenshotSpy).toHaveBeenCalledWith({
85
85
  browserInstance,
86
- origin: 'viewport',
86
+ origin: 'document',
87
87
  clip: { x: 10, y: 20, width: 100, height: 200 }
88
88
  });
89
89
  expect(takeWebElementScreenshotSpy).not.toHaveBeenCalled();
90
90
  expect(makeCroppedBase64ImageSpy).not.toHaveBeenCalled();
91
91
  });
92
- it('should fallback to document screenshot when viewport fails with zero dimensions error', async () => {
93
- takeBase64BiDiScreenshotSpy.mockRejectedValueOnce(new Error('WebDriver Bidi command "browsingContext.captureScreenshot" failed with error: unable to capture screen - Unable to capture screenshot with zero dimensions'));
94
- const result = await takeElementScreenshot(browserInstance, baseOptions, true);
92
+ //
93
+ // We intentionally rely on BiDi with origin: 'document' only. If that
94
+ // ever fails, we surface the underlying error instead of silently
95
+ // falling back to a different origin with mismatched coordinates.
96
+ it('should scroll element into view when autoElementScroll is enabled', async () => {
97
+ const optionsWithScroll = { ...baseOptions, autoElementScroll: true };
98
+ executeMock.mockResolvedValueOnce(100); // previous scroll position
99
+ const result = await takeElementScreenshot(browserInstance, optionsWithScroll, true);
95
100
  expect(result).toEqual({
96
101
  base64Image: 'bidi-screenshot-data',
97
102
  isWebDriverElementScreenshot: false
98
103
  });
99
- expect(takeBase64BiDiScreenshotSpy).toHaveBeenCalledTimes(2);
100
- expect(takeBase64BiDiScreenshotSpy.mock.calls[0][0]).toEqual({
101
- browserInstance,
102
- origin: 'viewport',
103
- clip: { x: 10, y: 20, width: 100, height: 200 }
104
- });
105
- expect(takeBase64BiDiScreenshotSpy.mock.calls[1][0]).toEqual({
106
- browserInstance,
107
- origin: 'document',
108
- clip: { x: 10, y: 20, width: 100, height: 200 }
109
- });
104
+ // First call: scrollElementIntoView, second call: scrollToPosition (restore)
105
+ expect(executeMock).toHaveBeenCalledTimes(2);
106
+ expect(executeMock.mock.calls[0]).toMatchSnapshot();
107
+ expect(executeMock.mock.calls[1]).toMatchSnapshot();
108
+ expect(waitForSpy).toHaveBeenCalledWith(100);
110
109
  });
111
- it('should throw error when BiDi screenshot fails with non-zero dimension error', async () => {
112
- const error = new Error('Some other BiDi error');
113
- takeBase64BiDiScreenshotSpy.mockRejectedValueOnce(error);
114
- await expect(takeElementScreenshot(browserInstance, baseOptions, true)).rejects.toThrow(error);
115
- expect(takeBase64BiDiScreenshotSpy).toHaveBeenCalledTimes(1);
116
- expect(takeWebElementScreenshotSpy).not.toHaveBeenCalled();
110
+ it('should not restore scroll when autoElementScroll is enabled but no previous position', async () => {
111
+ const optionsWithScroll = { ...baseOptions, autoElementScroll: true };
112
+ executeMock.mockResolvedValueOnce(undefined); // no previous position
113
+ await takeElementScreenshot(browserInstance, optionsWithScroll, true);
114
+ // Only the scrollElementIntoView call, no restore
115
+ expect(executeMock).toHaveBeenCalledTimes(1);
116
+ expect(waitForSpy).toHaveBeenCalledWith(100);
117
117
  });
118
118
  });
119
119
  describe('Legacy screenshots', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/image-comparison-core",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "author": "Wim Selles - wswebcreation",
5
5
  "description": "Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework",
6
6
  "keywords": [
@@ -28,10 +28,10 @@
28
28
  "dependencies": {
29
29
  "jimp": "^1.6.0",
30
30
  "@wdio/logger": "^9.18.0",
31
- "@wdio/types": "^9.20.0"
31
+ "@wdio/types": "^9.25.0"
32
32
  },
33
33
  "devDependencies": {
34
- "webdriverio": "^9.23.0"
34
+ "webdriverio": "^9.25.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"