@wdio/ocr-service 2.1.0 → 2.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.
package/CHANGELOG.md CHANGED
@@ -1,188 +1,206 @@
1
1
  # @wdio/ocr-service
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 786248e: Upgrade Jimp to the latest major
8
+
9
+ ## 2.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ # d76044f 🐛 Fix ERR_BUFFER_OUT_OF_BOUNDS for multiremote
14
+
15
+ Functions in utils such as `getData.ts` used the global `browser`, but this is not browser is not the browser making for example the `ocrClick` function call when the we are running in the multiremote context. This could lead to `ERR_BUFFER_OUT_OF_BOUNDS` error. This release fixes that error.
16
+
17
+ # Committers: 1
18
+
19
+ - Chanatan Charnkijtawarush ([@ccharnkij](https://github.com/ccharnkij))
20
+
3
21
  ## 2.1.0
4
22
 
5
23
  ### Minor Changes
6
24
 
7
- - f5f8041: fix click duration for 0ms
25
+ - f5f8041: fix click duration for 0ms
8
26
 
9
27
  ### Committers: 1
10
28
 
11
- - Fabien CELLIER ([@lacell75](https://github.com/lacell75))
29
+ - Fabien CELLIER ([@lacell75](https://github.com/lacell75))
12
30
 
13
31
  ## 2.0.0
14
32
 
15
33
  ### Major Changes
16
34
 
17
- - 9fdb2d2: feat: work with V9
35
+ - 9fdb2d2: feat: work with V9
18
36
 
19
37
  ## 1.0.5
20
38
 
21
39
  ### Patch Changes
22
40
 
23
- - 85a1d82: # 🐛 Bug Fixes
41
+ - 85a1d82: # 🐛 Bug Fixes
24
42
 
25
- Fix issues:
43
+ Fix issues:
26
44
 
27
- - [438](https://github.com/webdriverio/visual-testing/issues/438): resizeDimensions not working
28
- - [448](https://github.com/webdriverio/visual-testing/issues/448): hideElements and removeElements` don't work for native apps
45
+ - [438](https://github.com/webdriverio/visual-testing/issues/438): resizeDimensions not working
46
+ - [448](https://github.com/webdriverio/visual-testing/issues/448): hideElements and removeElements` don't work for native apps
29
47
 
30
- # 💅 Polish
48
+ # 💅 Polish
31
49
 
32
- - update dependencies
50
+ - update dependencies
33
51
 
34
- # Committers: 1
52
+ # Committers: 1
35
53
 
36
- - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
54
+ - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
37
55
 
38
56
  ## 1.0.4
39
57
 
40
58
  ### Patch Changes
41
59
 
42
- - 0b01b64: ### @wdio/visual-service
43
-
44
- #### 🚀 New Features
45
-
46
- **Added Reporting output**
47
- You now have the option to export the compare results into a JSON report file. By enabling the module option `createJsonReportFiles: true`, each image that is compared will create a report stored in the `actual` folder, next to each `actual` image result.
48
-
49
- The output will look like this:
50
-
51
- ```json
52
- {
53
- "parent": "check methods",
54
- "test": "should fail comparing with a baseline",
55
- "tag": "examplePageFail",
56
- "instanceData": {
57
- "browser": {
58
- "name": "chrome-headless-shell",
59
- "version": "126.0.6478.183"
60
- },
61
- "platform": {
62
- "name": "mac",
63
- "version": "not-known"
64
- }
60
+ - 0b01b64: ### @wdio/visual-service
61
+
62
+ #### 🚀 New Features
63
+
64
+ **Added Reporting output**
65
+ You now have the option to export the compare results into a JSON report file. By enabling the module option `createJsonReportFiles: true`, each image that is compared will create a report stored in the `actual` folder, next to each `actual` image result.
66
+
67
+ The output will look like this:
68
+
69
+ ```json
70
+ {
71
+ "parent": "check methods",
72
+ "test": "should fail comparing with a baseline",
73
+ "tag": "examplePageFail",
74
+ "instanceData": {
75
+ "browser": {
76
+ "name": "chrome-headless-shell",
77
+ "version": "126.0.6478.183"
78
+ },
79
+ "platform": {
80
+ "name": "mac",
81
+ "version": "not-known"
82
+ }
83
+ },
84
+ "commandName": "checkScreen",
85
+ "boundingBoxes": {
86
+ "diffBoundingBoxes": [
87
+ {
88
+ "left": 1088,
89
+ "top": 717,
90
+ "right": 1186,
91
+ "bottom": 730
92
+ }
93
+ //....
94
+ ],
95
+ "ignoredBoxes": [
96
+ {
97
+ "left": 159,
98
+ "top": 652,
99
+ "right": 356,
100
+ "bottom": 703
101
+ }
102
+ //...
103
+ ]
104
+ },
105
+ "fileData": {
106
+ "actualFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/actual/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
107
+ "baselineFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/localBaseline/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
108
+ "diffFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/diff/desktop_chrome-headless-shell/examplePageFail-local-chrome-latest-1366x768png",
109
+ "fileName": "examplePageFail-local-chrome-latest-1366x768.png",
110
+ "size": {
111
+ "actual": {
112
+ "height": 768,
113
+ "width": 1366
65
114
  },
66
- "commandName": "checkScreen",
67
- "boundingBoxes": {
68
- "diffBoundingBoxes": [
69
- {
70
- "left": 1088,
71
- "top": 717,
72
- "right": 1186,
73
- "bottom": 730
74
- }
75
- //....
76
- ],
77
- "ignoredBoxes": [
78
- {
79
- "left": 159,
80
- "top": 652,
81
- "right": 356,
82
- "bottom": 703
83
- }
84
- //...
85
- ]
115
+ "baseline": {
116
+ "height": 768,
117
+ "width": 1366
86
118
  },
87
- "fileData": {
88
- "actualFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/actual/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
89
- "baselineFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/localBaseline/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
90
- "diffFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/diff/desktop_chrome-headless-shell/examplePageFail-local-chrome-latest-1366x768png",
91
- "fileName": "examplePageFail-local-chrome-latest-1366x768.png",
92
- "size": {
93
- "actual": {
94
- "height": 768,
95
- "width": 1366
96
- },
97
- "baseline": {
98
- "height": 768,
99
- "width": 1366
100
- },
101
- "diff": {
102
- "height": 768,
103
- "width": 1366
104
- }
105
- }
106
- },
107
- "misMatchPercentage": "12.90",
108
- "rawMisMatchPercentage": 12.900729014153246
109
- }
110
- ```
119
+ "diff": {
120
+ "height": 768,
121
+ "width": 1366
122
+ }
123
+ }
124
+ },
125
+ "misMatchPercentage": "12.90",
126
+ "rawMisMatchPercentage": 12.900729014153246
127
+ }
128
+ ```
111
129
 
112
- When all tests are executed, a new JSON file with the collection of the comparisons will be generated and can be found in the root of your actual folder. The data is grouped by:
130
+ When all tests are executed, a new JSON file with the collection of the comparisons will be generated and can be found in the root of your actual folder. The data is grouped by:
113
131
 
114
- - `describe` for Jasmine/Mocha or `Feature` for CucumberJS
115
- - `it` for Jasmine/Mocha or `Scenario` for CucumberJS
132
+ - `describe` for Jasmine/Mocha or `Feature` for CucumberJS
133
+ - `it` for Jasmine/Mocha or `Scenario` for CucumberJS
116
134
 
117
- and then sorted by:
135
+ and then sorted by:
118
136
 
119
- - `commandName`, which are the compare method names used to compare the images
120
- - `instanceData`, browser first, then device, then platform
137
+ - `commandName`, which are the compare method names used to compare the images
138
+ - `instanceData`, browser first, then device, then platform
121
139
 
122
- it will look like this
140
+ it will look like this
123
141
 
124
- ```json
125
- [
142
+ ```json
143
+ [
144
+ {
145
+ "description": "check methods",
146
+ "data": [
126
147
  {
127
- "description": "check methods",
128
- "data": [
129
- {
130
- "test": "should fail comparing with a baseline",
131
- "data": [
132
- {
133
- "tag": "examplePageFail",
134
- "instanceData": {},
135
- "commandName": "checkScreen",
136
- "framework": "mocha",
137
- "boundingBoxes": {
138
- "diffBoundingBoxes": [],
139
- "ignoredBoxes": []
140
- },
141
- "fileData": {},
142
- "misMatchPercentage": "14.34",
143
- "rawMisMatchPercentage": 14.335403703025868
144
- },
145
- {
146
- "tag": "exampleElementFail",
147
- "instanceData": {},
148
- "commandName": "checkElement",
149
- "framework": "mocha",
150
- "boundingBoxes": {
151
- "diffBoundingBoxes": [],
152
- "ignoredBoxes": []
153
- },
154
- "fileData": {},
155
- "misMatchPercentage": "1.34",
156
- "rawMisMatchPercentage": 1.335403703025868
157
- }
158
- ]
159
- }
160
- ]
148
+ "test": "should fail comparing with a baseline",
149
+ "data": [
150
+ {
151
+ "tag": "examplePageFail",
152
+ "instanceData": {},
153
+ "commandName": "checkScreen",
154
+ "framework": "mocha",
155
+ "boundingBoxes": {
156
+ "diffBoundingBoxes": [],
157
+ "ignoredBoxes": []
158
+ },
159
+ "fileData": {},
160
+ "misMatchPercentage": "14.34",
161
+ "rawMisMatchPercentage": 14.335403703025868
162
+ },
163
+ {
164
+ "tag": "exampleElementFail",
165
+ "instanceData": {},
166
+ "commandName": "checkElement",
167
+ "framework": "mocha",
168
+ "boundingBoxes": {
169
+ "diffBoundingBoxes": [],
170
+ "ignoredBoxes": []
171
+ },
172
+ "fileData": {},
173
+ "misMatchPercentage": "1.34",
174
+ "rawMisMatchPercentage": 1.335403703025868
175
+ }
176
+ ]
161
177
  }
162
- ]
163
- ```
178
+ ]
179
+ }
180
+ ]
181
+ ```
164
182
 
165
- The report data will give you the opportunity to build your own visual report without doing all the magic and data collection yourself.
183
+ The report data will give you the opportunity to build your own visual report without doing all the magic and data collection yourself.
166
184
 
167
- ### webdriver-image-comparison
185
+ ### webdriver-image-comparison
168
186
 
169
- #### 🚀 New Features
187
+ #### 🚀 New Features
170
188
 
171
- - Add support to generate single JSON report files
189
+ - Add support to generate single JSON report files
172
190
 
173
- ### @wdio/ocr-service
191
+ ### @wdio/ocr-service
174
192
 
175
- #### 💅 Polish
193
+ #### 💅 Polish
176
194
 
177
- - Refactored the CLI to use `@inquirer/prompts` instead of `inquirer`
195
+ - Refactored the CLI to use `@inquirer/prompts` instead of `inquirer`
178
196
 
179
- ### Committers: 1
197
+ ### Committers: 1
180
198
 
181
- - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
199
+ - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
182
200
 
183
- ```
201
+ ```
184
202
 
185
- ```
203
+ ```
186
204
 
187
205
  ## 1.0.3
188
206
 
@@ -194,44 +212,44 @@ Update deps
194
212
 
195
213
  # Committers: 1
196
214
 
197
- - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
215
+ - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
198
216
 
199
217
  ## 1.0.2
200
218
 
201
219
  ### Patch Changes
202
220
 
203
- - 6e1e478: Fix contrast and languages
221
+ - 6e1e478: Fix contrast and languages
204
222
 
205
223
  ## 1.0.1
206
224
 
207
225
  ### Patch Changes
208
226
 
209
- - 083ad82: Fixed OCR cli
227
+ - 083ad82: Fixed OCR cli
210
228
 
211
229
  ## 1.0.0
212
230
 
213
231
  ### Major Changes
214
232
 
215
- - a924dfc: # 🚀 New Feature
233
+ - a924dfc: # 🚀 New Feature
216
234
 
217
- Sometimes it can be hard to find an element in a mobile native app or desktop site, with an interactable Canvas, with the default [WebdriverIO selectors](https://webdriver.io/docs/selectors). In that case, it would be nice if you would be able to use something like OCR ([Optical Character Recognition](https://en.wikipedia.org/wiki/Optical_character_recognition)) to interact with elements on your device/screen.
235
+ Sometimes it can be hard to find an element in a mobile native app or desktop site, with an interactable Canvas, with the default [WebdriverIO selectors](https://webdriver.io/docs/selectors). In that case, it would be nice if you would be able to use something like OCR ([Optical Character Recognition](https://en.wikipedia.org/wiki/Optical_character_recognition)) to interact with elements on your device/screen.
218
236
 
219
- The new `@wdio/ocr-service` service provides you with the option to interact with elements based on **visible text**. It will provide multiple commands to:
237
+ The new `@wdio/ocr-service` service provides you with the option to interact with elements based on **visible text**. It will provide multiple commands to:
220
238
 
221
- - wait
222
- - search
223
- - and interact
239
+ - wait
240
+ - search
241
+ - and interact
224
242
 
225
- with an element, all based on text.
243
+ with an element, all based on text.
226
244
 
227
- The following commands will be added
245
+ The following commands will be added
228
246
 
229
- - `ocrGetText`
230
- - `ocrGetElementPositionByText`
231
- - `ocrWaitForTextDisplayed`
232
- - `ocrClickOnText`
233
- - `ocrSetValue`
247
+ - `ocrGetText`
248
+ - `ocrGetElementPositionByText`
249
+ - `ocrWaitForTextDisplayed`
250
+ - `ocrClickOnText`
251
+ - `ocrSetValue`
234
252
 
235
- A CLI command will also be provided to pre-check text received from the image, this can be run by using the command `npx ocr-service`. For a demo check this video
253
+ A CLI command will also be provided to pre-check text received from the image, this can be run by using the command `npx ocr-service`. For a demo check this video
236
254
 
237
- https://github.com/webdriverio/visual-testing/assets/11979740/af001bd8-3068-43f5-8b44-b320174883a8
255
+ https://github.com/webdriverio/visual-testing/assets/11979740/af001bd8-3068-43f5-8b44-b320174883a8
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAUA,eAAO,MAAM,mBAAmB,wHAI/B,CAAA"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAWA,eAAO,MAAM,mBAAmB,wHAI/B,CAAA"}
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ import getData from './utils/getData.js';
6
6
  import { createOcrDir } from './utils/index.js';
7
7
  import { isSystemTesseractAvailable } from './utils/tesseract.js';
8
8
  import { SUPPORTED_LANGUAGES } from './utils/constants.js';
9
+ import { remote } from 'webdriverio';
9
10
  export const CONFIG_HELPER_INTRO = `
10
11
  =============================
11
12
  🤖 WDIO OCR-Service Wizard 🧙
@@ -136,8 +137,10 @@ async function main() {
136
137
  contrast: parseFloat(advancedOptions),
137
138
  };
138
139
  }
140
+ // For cli use, empty browser context to pass into getData
141
+ const browser = await remote({ capabilities: { browserName: 'stub' }, automationProtocol: './protocol-stub.js' });
139
142
  console.log('\nProcessing image...\n');
140
- await getData(options);
143
+ await getData(browser, options);
141
144
  console.log('\nDone!');
142
145
  }
143
146
  main();
@@ -1,3 +1,3 @@
1
1
  import type { OcrClickOnTextOptions } from '../types.js';
2
- export default function ocrClickOnText(options: OcrClickOnTextOptions): Promise<void>;
2
+ export default function ocrClickOnText(this: WebdriverIO.Browser, options: OcrClickOnTextOptions): Promise<void>;
3
3
  //# sourceMappingURL=ocrClickOnText.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ocrClickOnText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrClickOnText.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGxD,wBAA8B,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B1F"}
1
+ {"version":3,"file":"ocrClickOnText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrClickOnText.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGxD,wBAA8B,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BrH"}
@@ -1,9 +1,8 @@
1
- import { browser } from '@wdio/globals';
2
1
  import ocrGetElementPositionByText from './ocrGetElementPositionByText.js';
3
2
  import { determineClickPoint } from '../utils/index.js';
4
3
  import { drawTarget } from '../utils/imageProcessing.js';
5
4
  export default async function ocrClickOnText(options) {
6
- const element = await ocrGetElementPositionByText(options);
5
+ const element = await ocrGetElementPositionByText.bind(this)(options);
7
6
  let { x, y } = determineClickPoint({ rectangles: element.dprPosition });
8
7
  const { relativePosition } = options;
9
8
  // Adjust the x and y coordinates based on the relative position
@@ -14,9 +13,9 @@ export default async function ocrClickOnText(options) {
14
13
  }
15
14
  // Draw a target on the image so a user can see where the click will happen
16
15
  await drawTarget({ filePath: element.filePath, targetX: x, targetY: y });
17
- const actionType = browser.isMobile ? 'touch' : 'mouse';
16
+ const actionType = this.isMobile ? 'touch' : 'mouse';
18
17
  const clickDuration = options.clickDuration ?? 500;
19
- await browser
18
+ await this
20
19
  .action('pointer', {
21
20
  parameters: { pointerType: actionType }
22
21
  })
@@ -1,3 +1,3 @@
1
1
  import type { OcrGetElementPositionByText, OcrGetElementPositionByTextOptions } from '../types.js';
2
- export default function ocrGetElementPositionByText(data: OcrGetElementPositionByTextOptions): Promise<OcrGetElementPositionByText>;
2
+ export default function ocrGetElementPositionByText(this: WebdriverIO.Browser, data: OcrGetElementPositionByTextOptions): Promise<OcrGetElementPositionByText>;
3
3
  //# sourceMappingURL=ocrGetElementPositionByText.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ocrGetElementPositionByText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrGetElementPositionByText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,2BAA2B,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAA;AAMhH,wBAA8B,2BAA2B,CACrD,IAAI,EAAE,kCAAkC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAuDtC"}
1
+ {"version":3,"file":"ocrGetElementPositionByText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrGetElementPositionByText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,2BAA2B,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAA;AAMhH,wBAA8B,2BAA2B,CACrD,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,IAAI,EAAE,kCAAkC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAuDtC"}
@@ -4,7 +4,7 @@ import { fuzzyFind } from '../utils/fuzzySearch.js';
4
4
  const log = logger('@wdio/ocr-service:ocrGetElementPositionByText');
5
5
  export default async function ocrGetElementPositionByText(data) {
6
6
  const { contrast, haystack, fuzzyFindOptions, isTesseractAvailable, language, ocrImagesPath, text, } = data;
7
- const textPositions = await getTextPositions({
7
+ const textPositions = await getTextPositions(this, {
8
8
  contrast,
9
9
  haystack,
10
10
  isTesseractAvailable,
@@ -1,3 +1,3 @@
1
1
  import type { OcrGetTextOptions } from '../types.js';
2
- export default function ocrGetText(options: OcrGetTextOptions): Promise<string>;
2
+ export default function ocrGetText(this: WebdriverIO.Browser, options: OcrGetTextOptions): Promise<string>;
3
3
  //# sourceMappingURL=ocrGetText.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ocrGetText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrGetText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,wBAA8B,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAIpF"}
1
+ {"version":3,"file":"ocrGetText.d.ts","sourceRoot":"","sources":["../../src/commands/ocrGetText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,wBAA8B,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/G"}
@@ -1,5 +1,5 @@
1
1
  import getData from '../utils/getData.js';
2
2
  export default async function ocrGetText(options) {
3
- const { text } = await getData(options);
3
+ const { text } = await getData(this, options);
4
4
  return text.replace(/\n\s*\n/g, '\n');
5
5
  }
@@ -1,3 +1,3 @@
1
1
  import type { OcrSetValueOptions } from '../types.js';
2
- export default function ocrSetValue(options: OcrSetValueOptions): Promise<void>;
2
+ export default function ocrSetValue(this: WebdriverIO.Browser, options: OcrSetValueOptions): Promise<void>;
3
3
  //# sourceMappingURL=ocrSetValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ocrSetValue.d.ts","sourceRoot":"","sources":["../../src/commands/ocrSetValue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,wBAA8B,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDpF"}
1
+ {"version":3,"file":"ocrSetValue.d.ts","sourceRoot":"","sources":["../../src/commands/ocrSetValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,wBAA8B,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmD/G"}
@@ -1,10 +1,9 @@
1
- import { driver } from '@wdio/globals';
2
1
  import sendKeys from '../utils/sendKeys.js';
3
2
  import ocrClickOnText from './ocrClickOnText.js';
4
3
  export default async function ocrSetValue(options) {
5
4
  const { contrast, clickDuration, haystack, fuzzyFindOptions, isTesseractAvailable, language, ocrImagesPath, submitValue = false, text, value, } = options;
6
5
  // 1. First click on the position of the text to make sure it is intractable
7
- await ocrClickOnText({
6
+ await ocrClickOnText.bind(this)({
8
7
  contrast,
9
8
  clickDuration,
10
9
  haystack,
@@ -15,22 +14,22 @@ export default async function ocrSetValue(options) {
15
14
  text,
16
15
  });
17
16
  // 2. If Mobile then a keyboard might be shown
18
- if (driver.isMobile) {
17
+ if (this.isMobile) {
19
18
  try {
20
19
  // Wait for 3 seconds for the keyboard to be shown
21
- await driver.waitUntil(async () => driver.isKeyboardShown(), { timeout: 3 * 1000 });
20
+ await this.waitUntil(async () => this.isKeyboardShown(), { timeout: 3 * 1000 });
22
21
  }
23
22
  catch (_ign) {
24
23
  // Keyboard is not shown
25
24
  }
26
25
  }
27
26
  // 3. Send the value to the active element
28
- await sendKeys(value, submitValue);
27
+ await sendKeys(this, value, submitValue);
29
28
  // 4. If Mobile then hide the keyboard
30
- if (driver.isMobile) {
29
+ if (this.isMobile) {
31
30
  try {
32
- await driver.hideKeyboard();
33
- await driver.waitUntil(async () => !(await driver.isKeyboardShown()), { timeout: 3 * 1000 });
31
+ await this.hideKeyboard();
32
+ await this.waitUntil(async () => !(await this.isKeyboardShown()), { timeout: 3 * 1000 });
34
33
  }
35
34
  catch (_ign) {
36
35
  // Keyboard is not present or not hidden
@@ -1,3 +1,3 @@
1
1
  import type { OcrWaitForTextDisplayedOptions } from '../types.js';
2
- export default function ocrWaitForTextDisplayed(options: OcrWaitForTextDisplayedOptions): Promise<import("../types.js").OcrGetElementPositionByText>;
2
+ export default function ocrWaitForTextDisplayed(this: WebdriverIO.Browser, options: OcrWaitForTextDisplayedOptions): Promise<import("../types.js").OcrGetElementPositionByText>;
3
3
  //# sourceMappingURL=ocrWaitForTextDisplayed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ocrWaitForTextDisplayed.d.ts","sourceRoot":"","sources":["../../src/commands/ocrWaitForTextDisplayed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAGjE,wBAA8B,uBAAuB,CACjD,OAAO,EAAE,8BAA8B,8DAW1C"}
1
+ {"version":3,"file":"ocrWaitForTextDisplayed.d.ts","sourceRoot":"","sources":["../../src/commands/ocrWaitForTextDisplayed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAGjE,wBAA8B,uBAAuB,CACjD,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,OAAO,EAAE,8BAA8B,8DAW1C"}
@@ -1,8 +1,7 @@
1
- import { driver } from '@wdio/globals';
2
1
  import ocrGetElementPositionByText from './ocrGetElementPositionByText.js';
3
2
  export default async function ocrWaitForTextDisplayed(options) {
4
3
  const { timeout, timeoutMsg } = options;
5
- return driver.waitUntil(async () => ocrGetElementPositionByText(options), {
4
+ return this.waitUntil(async () => ocrGetElementPositionByText.bind(this)(options), {
6
5
  timeout: timeout || 180000,
7
6
  timeoutMsg: timeoutMsg || `Could not find the text "${options.text}" within the requested time.`,
8
7
  });
package/dist/service.js CHANGED
@@ -83,7 +83,7 @@ export default class WdioOcrService {
83
83
  for (const [commandName, command] of Object.entries(ocrCommands)) {
84
84
  log.info(`Adding browser command "${commandName}" to browser object`);
85
85
  currentBrowser.addCommand(commandName, function (options) {
86
- return command({
86
+ return command.bind(this)({
87
87
  ...options,
88
88
  contrast: options?.contrast || self._ocrContrast,
89
89
  isTesseractAvailable,
package/dist/types.d.ts CHANGED
@@ -98,7 +98,7 @@ export type Words = Line & {
98
98
  wc: number;
99
99
  };
100
100
  export type TessaractDataOptions = {
101
- filePath: string;
101
+ filePath: `${string}.${string}`;
102
102
  language: string;
103
103
  };
104
104
  export type ParseWordData = {
@@ -108,7 +108,7 @@ export type ParseWordData = {
108
108
  export type GetTextPositionsOptions = DefaultMethodOptions & {};
109
109
  export type GetTextPositions = {
110
110
  dprPosition: Rectangles;
111
- filePath: string;
111
+ filePath: `${string}.${string}`;
112
112
  originalPosition: Rectangles;
113
113
  text: string;
114
114
  };
@@ -184,7 +184,7 @@ export type FuzzyElement = {
184
184
  /**
185
185
  * The path of the OCR screenshot
186
186
  */
187
- filePath: string;
187
+ filePath: `${string}.${string}`;
188
188
  /**
189
189
  * The original position
190
190
  */
@@ -231,10 +231,10 @@ export type ProcessImageOptions = {
231
231
  screenshot: string;
232
232
  };
233
233
  export type ProcessImage = {
234
- filePath: string;
234
+ filePath: `${string}.${string}`;
235
235
  };
236
236
  export type DrawHighlightedWords = {
237
- filePath: string;
237
+ filePath: `${string}.${string}`;
238
238
  highlights: Rectangles[];
239
239
  };
240
240
  export type ScreenshotSize = {
@@ -270,7 +270,7 @@ export type UnprocessedSystemStringElement = {
270
270
  };
271
271
  };
272
272
  export type TargetOptions = {
273
- filePath: string;
273
+ filePath: `${string}.${string}`;
274
274
  targetX: number;
275
275
  targetY: number;
276
276
  };
@@ -297,7 +297,7 @@ export type UnprocessedNodejsWord = {
297
297
  */
298
298
  export interface GetData extends GetOcrData {
299
299
  dpr: number;
300
- filePath: string;
300
+ filePath: `${string}.${string}`;
301
301
  }
302
302
  export type OcrGetElementPositionByText = {
303
303
  /**
@@ -309,7 +309,7 @@ export type OcrGetElementPositionByText = {
309
309
  /**
310
310
  * The path of the OCR screenshot
311
311
  */
312
- filePath: string;
312
+ filePath: `${string}.${string}`;
313
313
  /**
314
314
  * the matched string
315
315
  */
@@ -1 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AC;IAChB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAChC,CAAC,CAAC,EAAE,0BAA0B,EAAE,CAAC;CACrC,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,IAAI,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAClC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAE;IAC/B,IAAI,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAClC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE;QACC,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;CACL,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,OAAQ,SAAQ,UAAU;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,MAAM,2BAA2B,GAAG;IACtC;;;;OAIG;IACH,WAAW,EAAE,UAAU,CAAC;IACxB;;OAEG;IACH,QAAQ,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAChC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,gBAAgB,EAAE,UAAU,CAAC;IAC7B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACjB,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import type { GetData, GetDataOptions } from '../types.js';
2
- export default function getData(options: GetDataOptions): Promise<GetData>;
2
+ export default function getData(browser: WebdriverIO.Browser, options: GetDataOptions): Promise<GetData>;
3
3
  //# sourceMappingURL=getData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/utils/getData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAoB,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAA;AAM/F,wBAA8B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CA+E/E"}
1
+ {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/utils/getData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAA;AAM/F,wBAA8B,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CA+E7G"}
@@ -1,10 +1,9 @@
1
1
  import logger from '@wdio/logger';
2
- import { browser } from '@wdio/globals';
3
2
  import { getNodeOcrData, getSystemOcrData } from './tesseract.js';
4
3
  import { adjustElementBbox, getScreenshotSize, isRectanglesObject } from './index.js';
5
4
  import { drawHighlightedWords, processImage } from './imageProcessing.js';
6
5
  const log = logger('@wdio/ocr-service:getData');
7
- export default async function getData(options) {
6
+ export default async function getData(browser, options) {
8
7
  const { contrast, cliFile, haystack, isTesseractAvailable, language, ocrImagesPath, } = options;
9
8
  try {
10
9
  let dpr = 1;
@@ -18,7 +17,7 @@ export default async function getData(options) {
18
17
  else {
19
18
  screenshot = cliFile;
20
19
  }
21
- const { filePath } = await processImage({ contrast, isAndroid: browser.isAndroid = false, isIOS: browser.isIOS = false, ocrImagesPath, screenshot });
20
+ const { filePath } = await processImage({ contrast, isAndroid: browser.isAndroid, isIOS: browser.isIOS, ocrImagesPath, screenshot });
22
21
  let elementRectangles;
23
22
  let croppedFilePath;
24
23
  if (haystack) {
@@ -1,3 +1,3 @@
1
1
  import type { GetTextPositions, GetTextPositionsOptions } from '../types.js';
2
- export default function getTextPositions(options: GetTextPositionsOptions): Promise<GetTextPositions[]>;
2
+ export default function getTextPositions(browser: WebdriverIO.Browser, options: GetTextPositionsOptions): Promise<GetTextPositions[]>;
3
3
  //# sourceMappingURL=getTextPositions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTextPositions.d.ts","sourceRoot":"","sources":["../../src/utils/getTextPositions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAQ,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAElF,wBAA8B,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAa5G"}
1
+ {"version":3,"file":"getTextPositions.d.ts","sourceRoot":"","sources":["../../src/utils/getTextPositions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAQ,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAElF,wBAA8B,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAa1I"}
@@ -1,7 +1,7 @@
1
1
  import getData from './getData.js';
2
2
  import { getDprPositions } from './index.js';
3
- export default async function getTextPositions(options) {
4
- const { dpr, filePath, words } = await getData(options);
3
+ export default async function getTextPositions(browser, options) {
4
+ const { dpr, filePath, words } = await getData(browser, options);
5
5
  return (words
6
6
  .map(({ text, bbox }) => ({
7
7
  dprPosition: getDprPositions(JSON.parse(JSON.stringify(bbox)), dpr),
@@ -1 +1 @@
1
- {"version":3,"file":"imageProcessing.d.ts","sourceRoot":"","sources":["../../src/utils/imageProcessing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKzG,wBAAsB,YAAY,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,EAAC,mBAAmB,GAChI,OAAO,CAAC,YAAY,CAAC,CAyBvB;AAED,wBAAsB,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,iBAc7E;AAED,wBAAsB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,oBAAoB,iBA+BxF"}
1
+ {"version":3,"file":"imageProcessing.d.ts","sourceRoot":"","sources":["../../src/utils/imageProcessing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKzG,wBAAsB,YAAY,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,EAAC,mBAAmB,GAChI,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAED,wBAAsB,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,iBAc7E;AAED,wBAAsB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,oBAAoB,iBA+BxF"}
@@ -1,5 +1,5 @@
1
1
  import logger from '@wdio/logger';
2
- import Jimp from 'jimp';
2
+ import { intToRGBA, Jimp, rgbaToInt } from 'jimp';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -19,11 +19,12 @@ export async function processImage({ contrast, elementRectangles, isAndroid, isI
19
19
  const cropY = Math.max(0, elementRectangles.y);
20
20
  const cropWidth = Math.min(elementRectangles.width, screenshotSize.width - cropX);
21
21
  const cropHeight = Math.min(elementRectangles.height, screenshotSize.height - cropY);
22
- image.crop(cropX, cropY, cropWidth, cropHeight);
22
+ // image.crop(cropX, cropY, cropWidth, cropHeight)
23
+ image.crop({ w: cropWidth, h: cropHeight, x: cropX, y: cropY });
23
24
  fileName = `${platform}-${timestamp}-cropped.png`;
24
25
  filePath = join(ocrImagesPath, fileName);
25
26
  }
26
- await image.writeAsync(filePath);
27
+ await image.write(filePath);
27
28
  return { filePath };
28
29
  }
29
30
  export async function drawTarget({ filePath, targetX, targetY }) {
@@ -36,7 +37,7 @@ export async function drawTarget({ filePath, targetX, targetY }) {
36
37
  const xPosition = targetX - (targetImage.bitmap.width / 2);
37
38
  const yPosition = targetY - (targetImage.bitmap.height / 2);
38
39
  sourceImage.composite(targetImage, xPosition, yPosition);
39
- await sourceImage.writeAsync(filePath);
40
+ await sourceImage.write(filePath);
40
41
  }
41
42
  catch (error) {
42
43
  log.error('Failed to draw target on image:', error);
@@ -54,18 +55,18 @@ export async function drawHighlightedWords({ filePath, highlights }) {
54
55
  for (let x = left; x < left + width; x++) {
55
56
  // Get the current pixel color
56
57
  const currentColor = image.getPixelColor(x, y);
57
- const rgba = Jimp.intToRGBA(currentColor);
58
+ const rgba = intToRGBA(currentColor);
58
59
  // Calculate new color values using simple alpha blending
59
60
  const newR = (highlightColor.r * highlightColor.a) + (rgba.r * (1 - highlightColor.a));
60
61
  const newG = (highlightColor.g * highlightColor.a) + (rgba.g * (1 - highlightColor.a));
61
62
  const newB = (highlightColor.b * highlightColor.a) + (rgba.b * (1 - highlightColor.a));
62
63
  const newA = rgba.a; // Use original alpha to maintain image integrity
63
64
  // Set the new pixel color
64
- image.setPixelColor(Jimp.rgbaToInt(newR, newG, newB, newA), x, y);
65
+ image.setPixelColor(rgbaToInt(newR, newG, newB, newA), x, y);
65
66
  }
66
67
  }
67
68
  });
68
- await image.writeAsync(filePath);
69
+ await image.write(filePath);
69
70
  }
70
71
  catch (error) {
71
72
  log.error('Failed to highlight words on image:', error);
@@ -1,2 +1,2 @@
1
- export default function sendKeys(value: string, submitValue: boolean): Promise<void>;
1
+ export default function sendKeys(browser: WebdriverIO.Browser, value: string, submitValue: boolean): Promise<void>;
2
2
  //# sourceMappingURL=sendKeys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendKeys.d.ts","sourceRoot":"","sources":["../../src/utils/sendKeys.ts"],"names":[],"mappings":"AAGA,wBAA8B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBzF"}
1
+ {"version":3,"file":"sendKeys.d.ts","sourceRoot":"","sources":["../../src/utils/sendKeys.ts"],"names":[],"mappings":"AAEA,wBAA8B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBvH"}
@@ -1,6 +1,5 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { Key } from 'webdriverio';
3
- export default async function sendKeys(value, submitValue) {
2
+ export default async function sendKeys(browser, value, submitValue) {
4
3
  const actionChain = browser.action('key');
5
4
  [...value].forEach((char) => {
6
5
  actionChain.down(char);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wdio/ocr-service",
3
3
  "author": "Wim Selles - wswebcreation",
4
4
  "description": "A WebdriverIO service that is using Tesseract OCR for Desktop/Mobile Web and Mobile Native App tests.",
5
- "version": "2.1.0",
5
+ "version": "2.2.0",
6
6
  "license": "MIT",
7
7
  "homepage": "https://webdriver.io/docs/visual-testing",
8
8
  "repository": {
@@ -26,8 +26,8 @@
26
26
  "@wdio/logger": "^9.1.0",
27
27
  "@wdio/types": "^9.1.2",
28
28
  "fuse.js": "^7.0.0",
29
- "@inquirer/prompts": "5.5.0",
30
- "jimp": "^0.22.12",
29
+ "@inquirer/prompts": "6.0.1",
30
+ "jimp": "^1.6.0",
31
31
  "node-tesseract-ocr": "^2.2.1",
32
32
  "tesseract.js": "^5.1.1",
33
33
  "xml2js": "^0.6.2"