@wdio/ocr-service 2.1.0 → 2.1.1
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 +164 -152
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/commands/ocrClickOnText.d.ts +1 -1
- package/dist/commands/ocrClickOnText.d.ts.map +1 -1
- package/dist/commands/ocrClickOnText.js +3 -4
- package/dist/commands/ocrGetElementPositionByText.d.ts +1 -1
- package/dist/commands/ocrGetElementPositionByText.d.ts.map +1 -1
- package/dist/commands/ocrGetElementPositionByText.js +1 -1
- package/dist/commands/ocrGetText.d.ts +1 -1
- package/dist/commands/ocrGetText.d.ts.map +1 -1
- package/dist/commands/ocrGetText.js +1 -1
- package/dist/commands/ocrSetValue.d.ts +1 -1
- package/dist/commands/ocrSetValue.d.ts.map +1 -1
- package/dist/commands/ocrSetValue.js +7 -8
- package/dist/commands/ocrWaitForTextDisplayed.d.ts +1 -1
- package/dist/commands/ocrWaitForTextDisplayed.d.ts.map +1 -1
- package/dist/commands/ocrWaitForTextDisplayed.js +1 -2
- package/dist/service.js +1 -1
- package/dist/utils/getData.d.ts +1 -1
- package/dist/utils/getData.d.ts.map +1 -1
- package/dist/utils/getData.js +2 -3
- package/dist/utils/getTextPositions.d.ts +1 -1
- package/dist/utils/getTextPositions.d.ts.map +1 -1
- package/dist/utils/getTextPositions.js +2 -2
- package/dist/utils/sendKeys.d.ts +1 -1
- package/dist/utils/sendKeys.d.ts.map +1 -1
- package/dist/utils/sendKeys.js +1 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,188 +1,200 @@
|
|
|
1
1
|
# @wdio/ocr-service
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
# d76044f 🐛 Fix ERR_BUFFER_OUT_OF_BOUNDS for multiremote
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
# Committers: 1
|
|
12
|
+
|
|
13
|
+
- Chanatan Charnkijtawarush ([@ccharnkij](https://github.com/ccharnkij))
|
|
14
|
+
|
|
3
15
|
## 2.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
6
18
|
|
|
7
|
-
-
|
|
19
|
+
- f5f8041: fix click duration for 0ms
|
|
8
20
|
|
|
9
21
|
### Committers: 1
|
|
10
22
|
|
|
11
|
-
-
|
|
23
|
+
- Fabien CELLIER ([@lacell75](https://github.com/lacell75))
|
|
12
24
|
|
|
13
25
|
## 2.0.0
|
|
14
26
|
|
|
15
27
|
### Major Changes
|
|
16
28
|
|
|
17
|
-
-
|
|
29
|
+
- 9fdb2d2: feat: work with V9
|
|
18
30
|
|
|
19
31
|
## 1.0.5
|
|
20
32
|
|
|
21
33
|
### Patch Changes
|
|
22
34
|
|
|
23
|
-
-
|
|
35
|
+
- 85a1d82: # 🐛 Bug Fixes
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
Fix issues:
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
- [438](https://github.com/webdriverio/visual-testing/issues/438): resizeDimensions not working
|
|
40
|
+
- [448](https://github.com/webdriverio/visual-testing/issues/448): hideElements and removeElements` don't work for native apps
|
|
29
41
|
|
|
30
|
-
|
|
42
|
+
# 💅 Polish
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
- update dependencies
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
# Committers: 1
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
|
|
37
49
|
|
|
38
50
|
## 1.0.4
|
|
39
51
|
|
|
40
52
|
### Patch Changes
|
|
41
53
|
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
54
|
+
- 0b01b64: ### @wdio/visual-service
|
|
55
|
+
|
|
56
|
+
#### 🚀 New Features
|
|
57
|
+
|
|
58
|
+
**Added Reporting output**
|
|
59
|
+
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.
|
|
60
|
+
|
|
61
|
+
The output will look like this:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"parent": "check methods",
|
|
66
|
+
"test": "should fail comparing with a baseline",
|
|
67
|
+
"tag": "examplePageFail",
|
|
68
|
+
"instanceData": {
|
|
69
|
+
"browser": {
|
|
70
|
+
"name": "chrome-headless-shell",
|
|
71
|
+
"version": "126.0.6478.183"
|
|
72
|
+
},
|
|
73
|
+
"platform": {
|
|
74
|
+
"name": "mac",
|
|
75
|
+
"version": "not-known"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"commandName": "checkScreen",
|
|
79
|
+
"boundingBoxes": {
|
|
80
|
+
"diffBoundingBoxes": [
|
|
81
|
+
{
|
|
82
|
+
"left": 1088,
|
|
83
|
+
"top": 717,
|
|
84
|
+
"right": 1186,
|
|
85
|
+
"bottom": 730
|
|
86
|
+
}
|
|
87
|
+
//....
|
|
88
|
+
],
|
|
89
|
+
"ignoredBoxes": [
|
|
90
|
+
{
|
|
91
|
+
"left": 159,
|
|
92
|
+
"top": 652,
|
|
93
|
+
"right": 356,
|
|
94
|
+
"bottom": 703
|
|
95
|
+
}
|
|
96
|
+
//...
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
"fileData": {
|
|
100
|
+
"actualFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/actual/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
|
|
101
|
+
"baselineFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/localBaseline/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
|
|
102
|
+
"diffFilePath": "/Users/wswebcreation/Git/wdio/visual-testing/.tmp/diff/desktop_chrome-headless-shell/examplePageFail-local-chrome-latest-1366x768png",
|
|
103
|
+
"fileName": "examplePageFail-local-chrome-latest-1366x768.png",
|
|
104
|
+
"size": {
|
|
105
|
+
"actual": {
|
|
106
|
+
"height": 768,
|
|
107
|
+
"width": 1366
|
|
86
108
|
},
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
109
|
+
"baseline": {
|
|
110
|
+
"height": 768,
|
|
111
|
+
"width": 1366
|
|
106
112
|
},
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
"diff": {
|
|
114
|
+
"height": 768,
|
|
115
|
+
"width": 1366
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"misMatchPercentage": "12.90",
|
|
120
|
+
"rawMisMatchPercentage": 12.900729014153246
|
|
121
|
+
}
|
|
122
|
+
```
|
|
111
123
|
|
|
112
|
-
|
|
124
|
+
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
125
|
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
- `describe` for Jasmine/Mocha or `Feature` for CucumberJS
|
|
127
|
+
- `it` for Jasmine/Mocha or `Scenario` for CucumberJS
|
|
116
128
|
|
|
117
|
-
|
|
129
|
+
and then sorted by:
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
- `commandName`, which are the compare method names used to compare the images
|
|
132
|
+
- `instanceData`, browser first, then device, then platform
|
|
121
133
|
|
|
122
|
-
|
|
134
|
+
it will look like this
|
|
123
135
|
|
|
124
|
-
|
|
125
|
-
|
|
136
|
+
```json
|
|
137
|
+
[
|
|
138
|
+
{
|
|
139
|
+
"description": "check methods",
|
|
140
|
+
"data": [
|
|
126
141
|
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"rawMisMatchPercentage": 1.335403703025868
|
|
157
|
-
}
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
]
|
|
142
|
+
"test": "should fail comparing with a baseline",
|
|
143
|
+
"data": [
|
|
144
|
+
{
|
|
145
|
+
"tag": "examplePageFail",
|
|
146
|
+
"instanceData": {},
|
|
147
|
+
"commandName": "checkScreen",
|
|
148
|
+
"framework": "mocha",
|
|
149
|
+
"boundingBoxes": {
|
|
150
|
+
"diffBoundingBoxes": [],
|
|
151
|
+
"ignoredBoxes": []
|
|
152
|
+
},
|
|
153
|
+
"fileData": {},
|
|
154
|
+
"misMatchPercentage": "14.34",
|
|
155
|
+
"rawMisMatchPercentage": 14.335403703025868
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"tag": "exampleElementFail",
|
|
159
|
+
"instanceData": {},
|
|
160
|
+
"commandName": "checkElement",
|
|
161
|
+
"framework": "mocha",
|
|
162
|
+
"boundingBoxes": {
|
|
163
|
+
"diffBoundingBoxes": [],
|
|
164
|
+
"ignoredBoxes": []
|
|
165
|
+
},
|
|
166
|
+
"fileData": {},
|
|
167
|
+
"misMatchPercentage": "1.34",
|
|
168
|
+
"rawMisMatchPercentage": 1.335403703025868
|
|
169
|
+
}
|
|
170
|
+
]
|
|
161
171
|
}
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
```
|
|
164
176
|
|
|
165
|
-
|
|
177
|
+
The report data will give you the opportunity to build your own visual report without doing all the magic and data collection yourself.
|
|
166
178
|
|
|
167
|
-
|
|
179
|
+
### webdriver-image-comparison
|
|
168
180
|
|
|
169
|
-
|
|
181
|
+
#### 🚀 New Features
|
|
170
182
|
|
|
171
|
-
|
|
183
|
+
- Add support to generate single JSON report files
|
|
172
184
|
|
|
173
|
-
|
|
185
|
+
### @wdio/ocr-service
|
|
174
186
|
|
|
175
|
-
|
|
187
|
+
#### 💅 Polish
|
|
176
188
|
|
|
177
|
-
|
|
189
|
+
- Refactored the CLI to use `@inquirer/prompts` instead of `inquirer`
|
|
178
190
|
|
|
179
|
-
|
|
191
|
+
### Committers: 1
|
|
180
192
|
|
|
181
|
-
|
|
193
|
+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
|
|
182
194
|
|
|
183
|
-
|
|
195
|
+
```
|
|
184
196
|
|
|
185
|
-
|
|
197
|
+
```
|
|
186
198
|
|
|
187
199
|
## 1.0.3
|
|
188
200
|
|
|
@@ -194,44 +206,44 @@ Update deps
|
|
|
194
206
|
|
|
195
207
|
# Committers: 1
|
|
196
208
|
|
|
197
|
-
-
|
|
209
|
+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
|
|
198
210
|
|
|
199
211
|
## 1.0.2
|
|
200
212
|
|
|
201
213
|
### Patch Changes
|
|
202
214
|
|
|
203
|
-
-
|
|
215
|
+
- 6e1e478: Fix contrast and languages
|
|
204
216
|
|
|
205
217
|
## 1.0.1
|
|
206
218
|
|
|
207
219
|
### Patch Changes
|
|
208
220
|
|
|
209
|
-
-
|
|
221
|
+
- 083ad82: Fixed OCR cli
|
|
210
222
|
|
|
211
223
|
## 1.0.0
|
|
212
224
|
|
|
213
225
|
### Major Changes
|
|
214
226
|
|
|
215
|
-
-
|
|
227
|
+
- a924dfc: # 🚀 New Feature
|
|
216
228
|
|
|
217
|
-
|
|
229
|
+
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
230
|
|
|
219
|
-
|
|
231
|
+
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
232
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
233
|
+
- wait
|
|
234
|
+
- search
|
|
235
|
+
- and interact
|
|
224
236
|
|
|
225
|
-
|
|
237
|
+
with an element, all based on text.
|
|
226
238
|
|
|
227
|
-
|
|
239
|
+
The following commands will be added
|
|
228
240
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
241
|
+
- `ocrGetText`
|
|
242
|
+
- `ocrGetElementPositionByText`
|
|
243
|
+
- `ocrWaitForTextDisplayed`
|
|
244
|
+
- `ocrClickOnText`
|
|
245
|
+
- `ocrSetValue`
|
|
234
246
|
|
|
235
|
-
|
|
247
|
+
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
248
|
|
|
237
|
-
|
|
249
|
+
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":";
|
|
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":"
|
|
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 =
|
|
16
|
+
const actionType = this.isMobile ? 'touch' : 'mouse';
|
|
18
17
|
const clickDuration = options.clickDuration ?? 500;
|
|
19
|
-
await
|
|
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,
|
|
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,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":"
|
|
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 (
|
|
17
|
+
if (this.isMobile) {
|
|
19
18
|
try {
|
|
20
19
|
// Wait for 3 seconds for the keyboard to be shown
|
|
21
|
-
await
|
|
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 (
|
|
29
|
+
if (this.isMobile) {
|
|
31
30
|
try {
|
|
32
|
-
await
|
|
33
|
-
await
|
|
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":"
|
|
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
|
|
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/utils/getData.d.ts
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/utils/getData.js
CHANGED
|
@@ -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
|
|
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,
|
|
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),
|
package/dist/utils/sendKeys.d.ts
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/utils/sendKeys.js
CHANGED
|
@@ -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.
|
|
5
|
+
"version": "2.1.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://webdriver.io/docs/visual-testing",
|
|
8
8
|
"repository": {
|