@wdio/ocr-service 2.2.5 → 2.2.7
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 +25 -1
- package/dist/service.d.ts +1 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +22 -15
- package/dist/utils/getData.js +2 -2
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @wdio/ocr-service
|
|
2
2
|
|
|
3
|
+
## 2.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 75d31d1: fix: [657](#657) in multiremote, commands are now executed on the requested instances (ocrGetText no longer loop)
|
|
8
|
+
|
|
9
|
+
## Committers: 1
|
|
10
|
+
|
|
11
|
+
- P-Courteille ([@P-Courteille](https://github.com/P-Courteille))
|
|
12
|
+
|
|
13
|
+
## 2.2.6
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 42956e4: 🔧 Other
|
|
18
|
+
|
|
19
|
+
- 🆙 Updated dependencies
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
## Committers: 1
|
|
24
|
+
|
|
25
|
+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
|
|
26
|
+
|
|
3
27
|
## 2.2.5
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -8,7 +32,7 @@
|
|
|
8
32
|
|
|
9
33
|
### Committers: 1
|
|
10
34
|
|
|
11
|
-
-
|
|
35
|
+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
|
|
12
36
|
|
|
13
37
|
## 2.2.4
|
|
14
38
|
|
package/dist/service.d.ts
CHANGED
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAgB5C,MAAM,CAAC,OAAO,OAAO,cAAc;;IAC/B,OAAO,CAAC,QAAQ,CAAC,CAAsD;IACvE,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,YAAY,CAAQ;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAgB5C,MAAM,CAAC,OAAO,OAAO,cAAc;;IAC/B,OAAO,CAAC,QAAQ,CAAC,CAAsD;IACvE,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,qBAAqB,CAAS;gBAE1B,OAAO,EAAE,UAAU;IAQ/B;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB;IAIzE,MAAM,CACR,YAAY,EAAE,WAAW,CAAC,YAAY,EACtC,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB;CA4EpE"}
|
package/dist/service.js
CHANGED
|
@@ -20,10 +20,13 @@ export default class WdioOcrService {
|
|
|
20
20
|
_ocrDir;
|
|
21
21
|
_ocrLanguage;
|
|
22
22
|
_ocrContrast;
|
|
23
|
+
_isTesseractAvailable;
|
|
23
24
|
constructor(options) {
|
|
24
25
|
this._ocrDir = createOcrDir(options?.imagesFolder || DEFAULT_IMAGES_FOLDER);
|
|
25
26
|
this._ocrLanguage = options?.language || SUPPORTED_LANGUAGES.ENGLISH;
|
|
26
27
|
this._ocrContrast = options?.contrast || CONTRAST;
|
|
28
|
+
this._ocrLanguage = options?.language || SUPPORTED_LANGUAGES.ENGLISH;
|
|
29
|
+
this._isTesseractAvailable = isSystemTesseractAvailable();
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Set up the service if users want to use it in standalone mode
|
|
@@ -46,49 +49,53 @@ export default class WdioOcrService {
|
|
|
46
49
|
const browserNames = Object.keys(capabilities);
|
|
47
50
|
const self = this;
|
|
48
51
|
log.info(`Adding commands to Multi Browser: ${browserNames.join(', ')}`);
|
|
49
|
-
for (const browserName of browserNames) {
|
|
50
|
-
const multiremoteBrowser = browser;
|
|
51
|
-
const browserInstance = multiremoteBrowser.getInstance(browserName);
|
|
52
|
-
await this.#addCommandsToBrowser(browserInstance);
|
|
53
|
-
}
|
|
54
52
|
/**
|
|
55
|
-
* Add all
|
|
56
|
-
* on each browser in the Multi Remote.
|
|
53
|
+
* Add all commands to the global browser object that will execute on each browser in the Multi Remote.
|
|
57
54
|
*/
|
|
58
|
-
for (const
|
|
59
|
-
browser.addCommand(
|
|
55
|
+
for (const commandName of Object.keys(ocrCommands)) {
|
|
56
|
+
browser.addCommand(commandName, async function (...args) {
|
|
60
57
|
const returnData = {};
|
|
61
58
|
if (typeof args[0] === 'object' && args[0] !== null) {
|
|
62
59
|
const options = args[0];
|
|
60
|
+
options.ocrImagesPath = options?.imagesFolder || self._ocrDir;
|
|
63
61
|
options.contrast = options?.contrast || self._ocrContrast;
|
|
62
|
+
options.language = options?.language || self._ocrLanguage;
|
|
63
|
+
options.isTesseractAvailable = self._isTesseractAvailable;
|
|
64
64
|
args[0] = options;
|
|
65
65
|
}
|
|
66
66
|
for (const browserName of browserNames) {
|
|
67
67
|
const multiremoteBrowser = browser;
|
|
68
68
|
const browserInstance = multiremoteBrowser.getInstance(browserName);
|
|
69
|
-
if (typeof browserInstance[
|
|
70
|
-
returnData[browserName] = await browserInstance[
|
|
69
|
+
if (typeof browserInstance[commandName] === 'function') {
|
|
70
|
+
returnData[browserName] = await browserInstance[commandName].apply(browserInstance, args);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
-
throw new Error(`Command ${
|
|
73
|
+
throw new Error(`Command ${commandName} is not a function on the browser instance ${browserName}`);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return returnData;
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Add all commands to each instance (but Single Remote version)
|
|
81
|
+
*/
|
|
82
|
+
for (const browserName of browserNames) {
|
|
83
|
+
const multiremoteBrowser = browser;
|
|
84
|
+
const browserInstance = multiremoteBrowser.getInstance(browserName);
|
|
85
|
+
await this.#addCommandsToBrowser(browserInstance);
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
async #addCommandsToBrowser(currentBrowser) {
|
|
81
|
-
const isTesseractAvailable = isSystemTesseractAvailable();
|
|
82
89
|
const self = this;
|
|
83
90
|
for (const [commandName, command] of Object.entries(ocrCommands)) {
|
|
84
91
|
log.info(`Adding browser command "${commandName}" to browser object`);
|
|
85
92
|
currentBrowser.addCommand(commandName, function (options) {
|
|
86
93
|
return command.bind(this)({
|
|
87
94
|
...options,
|
|
95
|
+
ocrImagesPath: self._ocrDir,
|
|
88
96
|
contrast: options?.contrast || self._ocrContrast,
|
|
89
|
-
isTesseractAvailable,
|
|
90
97
|
language: options?.language || self._ocrLanguage,
|
|
91
|
-
|
|
98
|
+
isTesseractAvailable: self._isTesseractAvailable
|
|
92
99
|
});
|
|
93
100
|
});
|
|
94
101
|
}
|
package/dist/utils/getData.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import logger from '@wdio/logger';
|
|
2
2
|
import { getNodeOcrData, getSystemOcrData } from './tesseract.js';
|
|
3
|
-
import { adjustElementBbox,
|
|
3
|
+
import { adjustElementBbox, getBase64ScreenshotSize, isRectanglesObject } from './index.js';
|
|
4
4
|
import { drawHighlightedWords, processImage } from './imageProcessing.js';
|
|
5
5
|
const log = logger('@wdio/ocr-service:getData');
|
|
6
6
|
export default async function getData(browser, options) {
|
|
@@ -11,7 +11,7 @@ export default async function getData(browser, options) {
|
|
|
11
11
|
if (!cliFile) {
|
|
12
12
|
const screenSize = await browser.getWindowSize();
|
|
13
13
|
screenshot = await browser.takeScreenshot();
|
|
14
|
-
const { width } =
|
|
14
|
+
const { width } = getBase64ScreenshotSize(screenshot);
|
|
15
15
|
dpr = width / screenSize.width;
|
|
16
16
|
}
|
|
17
17
|
else {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChainablePromiseElement } from 'webdriverio';
|
|
2
2
|
import type { ClickPoint, DetermineClickPointOptions, Rectangles, RectReturn, ScreenshotSize } from '../types.js';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getBase64ScreenshotSize(screenshot: string): ScreenshotSize;
|
|
4
4
|
export declare function getDprPositions(values: Rectangles, dpr: number): Rectangles;
|
|
5
5
|
/**
|
|
6
6
|
* Determine the click point
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,0BAA0B,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,0BAA0B,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAK1E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAO3E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,UAAU,CAMnF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,GAAG,UAAU,CAOvF;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKvD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,GAAG,uBAAuB,GAAG,UAAU,GAAG,OAAO,CAM3G"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { mkdirSync } from 'node:fs';
|
|
3
|
-
export function
|
|
3
|
+
export function getBase64ScreenshotSize(screenshot) {
|
|
4
4
|
return {
|
|
5
5
|
height: Math.round(Buffer.from(screenshot, 'base64').readUInt32BE(20)),
|
|
6
6
|
width: Math.round(Buffer.from(screenshot, 'base64').readUInt32BE(16)),
|
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.2.
|
|
5
|
+
"version": "2.2.7",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://webdriver.io/docs/visual-testing",
|
|
8
8
|
"repository": {
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@wdio/globals": "^9.
|
|
26
|
-
"@wdio/logger": "^9.
|
|
27
|
-
"@wdio/types": "^9.
|
|
25
|
+
"@wdio/globals": "^9.17.0",
|
|
26
|
+
"@wdio/logger": "^9.18.0",
|
|
27
|
+
"@wdio/types": "^9.16.2",
|
|
28
28
|
"fuse.js": "^7.1.0",
|
|
29
|
-
"@inquirer/prompts": "7.
|
|
29
|
+
"@inquirer/prompts": "7.6.0",
|
|
30
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"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/inquirer": "~9.0.
|
|
36
|
+
"@types/inquirer": "~9.0.8",
|
|
37
37
|
"@types/xml2js": "~0.4.14"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|