@wdio/ocr-service 2.0.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 CHANGED
@@ -1,5 +1,27 @@
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
+
15
+ ## 2.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - f5f8041: fix click duration for 0ms
20
+
21
+ ### Committers: 1
22
+
23
+ - Fabien CELLIER ([@lacell75](https://github.com/lacell75))
24
+
3
25
  ## 2.0.0
4
26
 
5
27
  ### Major Changes
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';
18
- const clickDuration = options.clickDuration ? options.clickDuration : 500;
19
- await browser
16
+ const actionType = this.isMobile ? 'touch' : 'mouse';
17
+ const clickDuration = options.clickDuration ?? 500;
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,
@@ -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,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.0.0",
5
+ "version": "2.1.1",
6
6
  "license": "MIT",
7
7
  "homepage": "https://webdriver.io/docs/visual-testing",
8
8
  "repository": {
@@ -22,14 +22,14 @@
22
22
  "type": "module",
23
23
  "types": "./dist/index.d.ts",
24
24
  "dependencies": {
25
- "@wdio/globals": "^9.0.7",
26
- "@wdio/logger": "^9.0.4",
27
- "@wdio/types": "^9.0.4",
25
+ "@wdio/globals": "^9.1.2",
26
+ "@wdio/logger": "^9.1.0",
27
+ "@wdio/types": "^9.1.2",
28
28
  "fuse.js": "^7.0.0",
29
- "@inquirer/prompts": "5.3.8",
29
+ "@inquirer/prompts": "5.5.0",
30
30
  "jimp": "^0.22.12",
31
31
  "node-tesseract-ocr": "^2.2.1",
32
- "tesseract.js": "^5.1.0",
32
+ "tesseract.js": "^5.1.1",
33
33
  "xml2js": "^0.6.2"
34
34
  },
35
35
  "devDependencies": {