@appium/images-plugin 4.2.7 → 5.0.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.
@@ -1,16 +1,17 @@
1
- import {errors} from 'appium/driver';
2
1
  import {util} from '@appium/support';
3
- import {log} from './logger';
2
+ import type {ActionSequence, Element, ExternalDriver, Rect} from '@appium/types';
3
+ import {errors} from 'appium/driver.js';
4
+
4
5
  import {
5
- IMAGE_STRATEGY,
6
6
  DEFAULT_SETTINGS,
7
- IMAGE_TAP_STRATEGIES,
8
- IMAGE_ELEMENT_PREFIX,
9
7
  IMAGE_EL_TAP_STRATEGY_W3C,
10
- } from './constants';
11
- import type {Rect, Element, ExternalDriver, ActionSequence} from '@appium/types';
12
- import type {ImageElementFinder} from './finder';
13
- import type {ImageSettings, Dimension, Position, ImageElementOpts} from './types';
8
+ IMAGE_ELEMENT_PREFIX,
9
+ IMAGE_STRATEGY,
10
+ IMAGE_TAP_STRATEGIES,
11
+ } from './constants.js';
12
+ import type {ImageElementFinder} from './finder.js';
13
+ import {log} from './logger.js';
14
+ import type {Dimension, ImageElementOpts, ImageSettings, Position} from './types.js';
14
15
 
15
16
  const TAP_DURATION_MS = 125;
16
17
 
@@ -27,14 +28,7 @@ export class ImageElement {
27
28
  readonly finder: ImageElementFinder | null;
28
29
  readonly containerRect: Rect | null;
29
30
 
30
- constructor({
31
- template,
32
- rect,
33
- score,
34
- match = null,
35
- finder = null,
36
- containerRect = null,
37
- }: ImageElementOpts) {
31
+ constructor({template, rect, score, match = null, finder = null, containerRect = null}: ImageElementOpts) {
38
32
  this.template = template;
39
33
  this.rect = rect;
40
34
  this.id = `${IMAGE_ELEMENT_PREFIX}${util.uuidV4()}`;
@@ -92,12 +86,7 @@ export class ImageElement {
92
86
  *
93
87
  * @returns the result of running a command
94
88
  */
95
- static async execute(
96
- driver: ExternalDriver,
97
- imgEl: ImageElement,
98
- cmd: string,
99
- ...args: any[]
100
- ): Promise<any> {
89
+ static async execute(driver: ExternalDriver, imgEl: ImageElement, cmd: string, ...args: any[]): Promise<any> {
101
90
  switch (cmd) {
102
91
  case 'click':
103
92
  return await imgEl.click(driver);
@@ -134,7 +123,6 @@ export class ImageElement {
134
123
  }
135
124
 
136
125
  /**
137
- *
138
126
  * @returns this image element as a WebElement
139
127
  */
140
128
  asElement(): Element {
@@ -273,16 +261,10 @@ export class ImageElement {
273
261
  * @param args - Rest of arguments for executeScripts
274
262
  * @returns WebDriver element with a special id prefix
275
263
  */
276
- async find(
277
- multiple: boolean,
278
- driver: ExternalDriver,
279
- ...args: any[]
280
- ): Promise<Element | Element[] | ImageElement> {
264
+ async find(multiple: boolean, driver: ExternalDriver, ...args: any[]): Promise<Element | Element[] | ImageElement> {
281
265
  const [strategy, selector] = args;
282
266
  if (strategy !== IMAGE_STRATEGY) {
283
- throw new errors.InvalidSelectorError(
284
- `Lookup strategies other than '${IMAGE_STRATEGY}' are not supported`,
285
- );
267
+ throw new errors.InvalidSelectorError(`Lookup strategies other than '${IMAGE_STRATEGY}' are not supported`);
286
268
  }
287
269
  if (!this.finder) {
288
270
  throw new Error('Finder is not available');
package/lib/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export {ImageElementPlugin, getImgElFromArgs} from './plugin';
2
- export {IMAGE_STRATEGY} from './constants';
3
- export {ImageElementFinder} from './finder';
4
- export {ImageElement} from './image-element';
5
- export * from './constants';
6
- export {compareImages} from './compare';
7
- export type * from './types';
1
+ export {compareImages} from './compare.js';
2
+ export {IMAGE_STRATEGY} from './constants.js';
3
+ export * from './constants.js';
4
+ export {ImageElementFinder} from './finder.js';
5
+ export {ImageElement} from './image-element.js';
6
+ export {getImgElFromArgs, ImageElementPlugin} from './plugin.js';
7
+ export type * from './types.js';
package/lib/logger.ts CHANGED
@@ -1,3 +1,3 @@
1
- import {logger} from 'appium/support';
1
+ import {logger} from 'appium/support.js';
2
2
 
3
3
  export const log = logger.getLogger('ImageElementPlugin');
package/lib/plugin.ts CHANGED
@@ -1,12 +1,13 @@
1
- import {errors} from 'appium/driver';
1
+ import type {MatchingOptions, OccurrenceOptions, SimilarityOptions} from '@appium/opencv';
2
2
  import {util} from '@appium/support';
3
- import {BasePlugin} from 'appium/plugin';
4
- import {compareImages} from './compare';
5
- import {ImageElementFinder} from './finder';
6
- import {ImageElement} from './image-element';
7
- import {IMAGE_STRATEGY, IMAGE_ELEMENT_PREFIX} from './constants';
8
- import type {ExternalDriver, Element, ActionSequence, MethodMap} from '@appium/types';
9
- import type {MatchingOptions, SimilarityOptions, OccurrenceOptions} from '@appium/opencv';
3
+ import type {ActionSequence, Element, ExternalDriver, MethodMap} from '@appium/types';
4
+ import {errors} from 'appium/driver.js';
5
+ import {BasePlugin} from 'appium/plugin.js';
6
+
7
+ import {compareImages} from './compare.js';
8
+ import {IMAGE_ELEMENT_PREFIX, IMAGE_STRATEGY} from './constants.js';
9
+ import {ImageElementFinder} from './finder.js';
10
+ import {ImageElement} from './image-element.js';
10
11
 
11
12
  export class ImageElementPlugin extends BasePlugin {
12
13
  // this plugin supports a non-standard 'compare images' command
@@ -40,28 +41,15 @@ export class ImageElementPlugin extends BasePlugin {
40
41
  return await compareImages(mode, firstImage, secondImage, options);
41
42
  }
42
43
 
43
- async findElement(
44
- next: () => Promise<any>,
45
- driver: ExternalDriver,
46
- ...args: any[]
47
- ): Promise<any> {
44
+ async findElement(next: () => Promise<any>, driver: ExternalDriver, ...args: any[]): Promise<any> {
48
45
  return await this._find(false, next, driver, ...args);
49
46
  }
50
47
 
51
- async findElements(
52
- next: () => Promise<any>,
53
- driver: ExternalDriver,
54
- ...args: any[]
55
- ): Promise<any> {
48
+ async findElements(next: () => Promise<any>, driver: ExternalDriver, ...args: any[]): Promise<any> {
56
49
  return await this._find(true, next, driver, ...args);
57
50
  }
58
51
 
59
- async handle(
60
- next: () => Promise<any>,
61
- driver: ExternalDriver,
62
- cmdName: string,
63
- ...args: any[]
64
- ): Promise<any> {
52
+ async handle(next: () => Promise<any>, driver: ExternalDriver, cmdName: string, ...args: any[]): Promise<any> {
65
53
  // if we have a command that involves an image element id, attempt to find the image element
66
54
  // and execute the command on it
67
55
  const imgElId = getImgElFromArgs(args);
@@ -106,9 +94,10 @@ export class ImageElementPlugin extends BasePlugin {
106
94
  throw new errors.NoSuchElementError();
107
95
  }
108
96
 
109
- // Add the element's center coordinates to the offset value.
110
- actionWithEl.x += imgEl.center.x;
111
- actionWithEl.y += imgEl.center.y;
97
+ // Add the element's center to the offset. An unset offset must count as
98
+ // zero, otherwise the resulting coordinate is NaN.
99
+ actionWithEl.x = (actionWithEl.x ?? 0) + imgEl.center.x;
100
+ actionWithEl.y = (actionWithEl.y ?? 0) + imgEl.center.y;
112
101
  // Set the origin to the viewport so that the external driver can process it using coordinates.
113
102
  delete actionWithEl.origin;
114
103
  }
package/lib/types.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type {Rect} from '@appium/types';
2
- import type {ImageElementFinder} from './finder';
3
1
  import type {MatchingResult, OccurrenceResult, SimilarityResult} from '@appium/opencv';
4
- import type {IMAGE_EL_TAP_STRATEGY_W3C, IMAGE_EL_TAP_STRATEGY_MJSONWP} from './constants';
2
+ import type {Rect} from '@appium/types';
3
+
4
+ import type {IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C} from './constants.js';
5
+ import type {ImageElementFinder} from './finder.js';
5
6
 
6
7
  /**
7
8
  * Image settings interface for device settings
package/package.json CHANGED
@@ -1,49 +1,59 @@
1
1
  {
2
2
  "name": "@appium/images-plugin",
3
- "version": "4.2.7",
3
+ "version": "5.0.0",
4
+ "gitHead": "b67de03966155ff052076c11c1c8f20cc2ba9134",
4
5
  "description": "Plugin for working with images and image elements in Appium",
5
6
  "keywords": [
7
+ "android",
6
8
  "automation",
9
+ "firefoxos",
10
+ "ios",
7
11
  "javascript",
8
12
  "selenium",
9
- "webdriver",
10
- "ios",
11
- "android",
12
- "firefoxos",
13
- "testing"
13
+ "testing",
14
+ "webdriver"
14
15
  ],
15
16
  "homepage": "https://appium.io",
16
17
  "bugs": {
17
18
  "url": "https://github.com/appium/appium/issues"
18
19
  },
20
+ "license": "Apache-2.0",
21
+ "author": "https://github.com/appium",
19
22
  "repository": {
20
23
  "type": "git",
21
24
  "url": "https://github.com/appium/appium.git",
22
25
  "directory": "packages/images-plugin"
23
26
  },
24
- "license": "Apache-2.0",
25
- "author": "https://github.com/appium",
26
- "main": "./build/lib/index.js",
27
- "types": "./build/lib/index.d.ts",
28
27
  "files": [
29
- "build",
28
+ "build/lib",
30
29
  "docs",
31
30
  "lib",
32
- "tsconfig.json",
33
- "!build/tsconfig.tsbuildinfo",
34
- "!build/test"
31
+ "tsconfig.json"
35
32
  ],
33
+ "type": "module",
34
+ "main": "./build/lib/index.js",
35
+ "types": "./build/lib/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./build/lib/index.d.ts",
39
+ "import": "./build/lib/index.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
36
46
  "scripts": {
37
47
  "test": "npm run test:unit",
38
48
  "test:smoke": "node ./build/lib/index.js",
39
- "test:unit": "mocha \"./test/unit/**/*.spec.*ts\"",
40
- "test:e2e": "mocha --exit --timeout 40s --slow 20s \"./test/e2e/**/*.spec.*ts\""
49
+ "test:unit": "node --test --experimental-test-module-mocks --enable-source-maps --test-timeout=5000 \"./build/test/unit/**/*.spec.js\"",
50
+ "test:e2e": "node --test --enable-source-maps --test-force-exit --test-concurrency=1 --test-timeout=20000 \"./build/test/e2e/**/*.spec.js\""
41
51
  },
42
52
  "dependencies": {
43
- "@appium/opencv": "4.1.6",
44
- "@appium/support": "7.2.5",
45
- "lru-cache": "11.5.1",
46
- "sharp": "0.35.1"
53
+ "@appium/opencv": "5.0.0",
54
+ "@appium/support": "7.2.7",
55
+ "lru-cache": "11.5.2",
56
+ "sharp": "0.35.3"
47
57
  },
48
58
  "peerDependencies": {
49
59
  "appium": "^3.0.0-beta.0"
@@ -55,9 +65,5 @@
55
65
  "appium": {
56
66
  "pluginName": "images",
57
67
  "mainClass": "ImageElementPlugin"
58
- },
59
- "publishConfig": {
60
- "access": "public"
61
- },
62
- "gitHead": "e6b583a2094f7919ef27b0dc28ebf42b3184852b"
68
+ }
63
69
  }
package/tsconfig.json CHANGED
@@ -5,16 +5,25 @@
5
5
  "checkJs": true,
6
6
  "esModuleInterop": true,
7
7
  "strict": true,
8
+ "module": "NodeNext",
9
+ "moduleResolution": "NodeNext",
8
10
  "paths": {
9
- "@appium/opencv": ["../opencv"]
11
+ "@appium/opencv": ["../opencv"],
12
+ "appium": ["../appium"],
13
+ "appium/driver.js": ["../appium/driver.d.ts"],
14
+ "appium/plugin.js": ["../appium/plugin.d.ts"],
15
+ "appium/support.js": ["../appium/support.d.ts"]
10
16
  },
11
- "types": ["mocha", "chai", "sinon", "chai-as-promised"]
17
+ "types": ["node"]
12
18
  },
13
19
  "extends": "@appium/tsconfig/tsconfig.plugin.json",
14
20
  "include": ["lib", "test"],
15
21
  "references": [
16
- {
17
- "path": "../opencv"
18
- }
22
+ {"path": "../opencv"},
23
+ {"path": "../base-plugin"},
24
+ {"path": "../logger"},
25
+ {"path": "../support"},
26
+ {"path": "../types"},
27
+ {"path": "../plugin-test-support"}
19
28
  ]
20
29
  }