@appium/images-plugin 4.0.4 → 4.1.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.
Files changed (47) hide show
  1. package/build/lib/compare.d.ts +8 -22
  2. package/build/lib/compare.d.ts.map +1 -1
  3. package/build/lib/compare.js +17 -23
  4. package/build/lib/compare.js.map +1 -1
  5. package/build/lib/constants.d.ts +13 -12
  6. package/build/lib/constants.d.ts.map +1 -1
  7. package/build/lib/constants.js +0 -31
  8. package/build/lib/constants.js.map +1 -1
  9. package/build/lib/finder.d.ts +22 -121
  10. package/build/lib/finder.d.ts.map +1 -1
  11. package/build/lib/finder.js +60 -100
  12. package/build/lib/finder.js.map +1 -1
  13. package/build/lib/image-element.d.ts +36 -108
  14. package/build/lib/image-element.d.ts.map +1 -1
  15. package/build/lib/image-element.js +45 -60
  16. package/build/lib/image-element.js.map +1 -1
  17. package/build/lib/index.d.ts +8 -0
  18. package/build/lib/index.d.ts.map +1 -0
  19. package/build/lib/index.js +30 -0
  20. package/build/lib/index.js.map +1 -0
  21. package/build/lib/logger.d.ts +1 -2
  22. package/build/lib/logger.d.ts.map +1 -1
  23. package/build/lib/logger.js +2 -2
  24. package/build/lib/logger.js.map +1 -1
  25. package/build/lib/plugin.d.ts +15 -34
  26. package/build/lib/plugin.d.ts.map +1 -1
  27. package/build/lib/plugin.js +12 -25
  28. package/build/lib/plugin.js.map +1 -1
  29. package/build/lib/types.d.ts +127 -0
  30. package/build/lib/types.d.ts.map +1 -0
  31. package/build/lib/types.js +3 -0
  32. package/build/lib/types.js.map +1 -0
  33. package/lib/compare.ts +100 -0
  34. package/lib/constants.ts +31 -0
  35. package/lib/{finder.js → finder.ts} +109 -136
  36. package/lib/{image-element.js → image-element.ts} +67 -85
  37. package/lib/index.ts +7 -0
  38. package/lib/logger.ts +3 -0
  39. package/lib/{plugin.js → plugin.ts} +42 -38
  40. package/lib/types.ts +187 -0
  41. package/package.json +14 -14
  42. package/tsconfig.json +3 -2
  43. package/LICENSE +0 -201
  44. package/index.js +0 -1
  45. package/lib/compare.js +0 -96
  46. package/lib/constants.js +0 -70
  47. package/lib/logger.js +0 -5
@@ -1,46 +1,33 @@
1
1
  import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
3
  import {util} from '@appium/support';
4
- import log from './logger';
4
+ import {log} from './logger';
5
5
  import {
6
- IMAGE_STRATEGY, DEFAULT_SETTINGS, IMAGE_TAP_STRATEGIES,
7
- IMAGE_ELEMENT_PREFIX, IMAGE_EL_TAP_STRATEGY_W3C,
6
+ IMAGE_STRATEGY,
7
+ DEFAULT_SETTINGS,
8
+ IMAGE_TAP_STRATEGIES,
9
+ IMAGE_ELEMENT_PREFIX,
10
+ IMAGE_EL_TAP_STRATEGY_W3C,
8
11
  } from './constants';
12
+ import type {Rect, Element, ExternalDriver, ActionSequence} from '@appium/types';
13
+ import {ImageElementFinder} from './finder';
14
+ import type {ImageSettings, Dimension, Position, ImageElementOpts} from './types';
9
15
 
10
16
  const TAP_DURATION_MS = 125;
11
17
 
12
- /**
13
- * @typedef Dimension
14
- * @property {number} width - width of rect
15
- * @property {number} height - height of rect
16
- */
17
-
18
- /**
19
- * @typedef Position
20
- * @property {number} x - x coordinate
21
- * @property {number} y - y coordinate
22
- */
23
-
24
- /**
25
- * @typedef ImageElementOpts
26
- * @property {Buffer} template - the image which was used to find this ImageElement
27
- * @property {Rect} rect - bounds of matched image element
28
- * @property {number} score The similarity score as a float number in range [0.0, 1.0].
29
- * 1.0 is the highest score (means both images are totally equal).
30
- * @property {Buffer?} match - the image which has matched marks. Defaults to null.
31
- * @property {import('./finder').default?} finder - the finder we can use to re-check stale elements
32
- * @property {import('@appium/types').Rect?} containerRect - The bounding
33
- * rectangle to limit the search in
34
- */
35
-
36
18
  /**
37
19
  * Representation of an "image element", which is simply a set of coordinates
38
20
  * and methods that can be used on that set of coordinates via the driver
39
21
  */
40
- export default class ImageElement {
41
- /**
42
- * @param {ImageElementOpts} options
43
- */
22
+ export class ImageElement {
23
+ readonly template: Buffer;
24
+ rect: Rect;
25
+ readonly id: string;
26
+ readonly match: Buffer | null;
27
+ readonly score: number;
28
+ readonly finder: ImageElementFinder | null;
29
+ readonly containerRect: Rect | null;
30
+
44
31
  constructor({
45
32
  template,
46
33
  rect,
@@ -48,7 +35,7 @@ export default class ImageElement {
48
35
  match = null,
49
36
  finder = null,
50
37
  containerRect = null,
51
- }) {
38
+ }: ImageElementOpts) {
52
39
  this.template = template;
53
40
  this.rect = rect;
54
41
  this.id = `${IMAGE_ELEMENT_PREFIX}${util.uuidV4()}`;
@@ -59,23 +46,23 @@ export default class ImageElement {
59
46
  }
60
47
 
61
48
  /**
62
- * @returns {Dimension} - dimension of element
49
+ * @returns dimension of element
63
50
  */
64
- get size() {
51
+ get size(): Dimension {
65
52
  return {width: this.rect.width, height: this.rect.height};
66
53
  }
67
54
 
68
55
  /**
69
- * @returns {Position} - coordinates of top-left corner of element
56
+ * @returns coordinates of top-left corner of element
70
57
  */
71
- get location() {
58
+ get location(): Position {
72
59
  return {x: this.rect.x, y: this.rect.y};
73
60
  }
74
61
 
75
62
  /**
76
- * @returns {Position} - coordinates of center of element
63
+ * @returns coordinates of center of element
77
64
  */
78
- get center() {
65
+ get center(): Position {
79
66
  return {
80
67
  x: this.rect.x + this.rect.width / 2,
81
68
  y: this.rect.y + this.rect.height / 2,
@@ -83,34 +70,33 @@ export default class ImageElement {
83
70
  }
84
71
 
85
72
  /**
86
- * @returns {string} - the base64-encoded original image used for matching
73
+ * @returns the base64-encoded original image used for matching
87
74
  */
88
- get originalImage() {
75
+ get originalImage(): string {
89
76
  return this.template.toString('base64');
90
77
  }
91
78
 
92
79
  /**
93
- * @returns {string|null} - the base64-encoded image which has matched marks
80
+ * @returns the base64-encoded image which has matched marks
94
81
  */
95
- get matchedImage() {
82
+ get matchedImage(): string | null {
96
83
  return this.match?.toString('base64') ?? null;
97
84
  }
98
85
 
99
86
  /**
100
87
  *
101
- * @returns {Element} - this image element as a WebElement
88
+ * @returns this image element as a WebElement
102
89
  */
103
- asElement() {
90
+ asElement(): Element {
104
91
  return util.wrapElement(this.id);
105
92
  }
106
93
 
107
94
  /**
108
- * @param {ImageElement} other - an ImageElement to compare with this one
95
+ * @param other - an ImageElement to compare with this one
109
96
  *
110
- * @returns {boolean} - whether the other element and this one have the same
111
- * properties
97
+ * @returns whether the other element and this one have the same properties
112
98
  */
113
- equals(other) {
99
+ equals(other: ImageElement): boolean {
114
100
  return (
115
101
  this.rect.x === other.rect.x &&
116
102
  this.rect.y === other.rect.y &&
@@ -123,12 +109,12 @@ export default class ImageElement {
123
109
  * Use a driver to tap the screen at the center of this ImageElement's
124
110
  * position
125
111
  *
126
- * @param {import('appium/driver').BaseDriver} driver - driver for calling actions with
112
+ * @param driver - driver for calling actions with
127
113
  */
128
- async click(driver) {
114
+ async click(driver: ExternalDriver): Promise<void> {
129
115
  // before we click we need to make sure the element is actually still there
130
116
  // where we expect it to be
131
- const settings = {...DEFAULT_SETTINGS, ...driver.settings.getSettings()};
117
+ const settings: ImageSettings = {...DEFAULT_SETTINGS, ...driver.settings.getSettings()};
132
118
  const {
133
119
  autoUpdateImageElementPosition: updatePos,
134
120
  checkForImageElementStaleness,
@@ -144,19 +130,20 @@ export default class ImageElement {
144
130
  );
145
131
  }
146
132
 
147
- let newImgEl;
133
+ let newImgEl: ImageElement | undefined;
148
134
  if (checkForImageElementStaleness || updatePos) {
149
135
  log.info('Checking image element for staleness before clicking');
150
136
  try {
151
- newImgEl = /** @type {ImageElement} */ (await (/** @type {import('./finder').default} */ (this.finder))
152
- .findByImage(
153
- this.template, driver, {
154
- shouldCheckStaleness: true,
155
- // Set ignoreDefaultImageTemplateScale because this.template is device screenshot based image
156
- // managed inside Appium after finidng image by template which managed by a user
157
- ignoreDefaultImageTemplateScale: true,
158
- containerRect: this.containerRect,
159
- }));
137
+ if (!this.finder) {
138
+ throw new errors.StaleElementReferenceError();
139
+ }
140
+ newImgEl = (await this.finder.findByImage(this.template, driver, {
141
+ shouldCheckStaleness: true,
142
+ // Set ignoreDefaultImageTemplateScale because this.template is device screenshot based image
143
+ // managed inside Appium after finidng image by template which managed by a user
144
+ ignoreDefaultImageTemplateScale: true,
145
+ containerRect: this.containerRect,
146
+ })) as ImageElement;
160
147
  } catch {
161
148
  throw new errors.StaleElementReferenceError();
162
149
  }
@@ -188,7 +175,7 @@ export default class ImageElement {
188
175
  if (imageElementTapStrategy === IMAGE_EL_TAP_STRATEGY_W3C) {
189
176
  // set up a W3C action to click on the image by position
190
177
  log.info('Will tap using W3C actions');
191
- const action = {
178
+ const action: ActionSequence = {
192
179
  type: 'pointer',
193
180
  id: 'mouse',
194
181
  parameters: {pointerType: 'touch'},
@@ -231,34 +218,36 @@ export default class ImageElement {
231
218
  /**
232
219
  * Perform lookup of image element(s) inside of the current element
233
220
  *
234
- * @param {boolean} multiple - Whether to lookup multiple elements
235
- * @param {import('appium/driver').BaseDriver} driver - The driver to use for commands
236
- * @param {string[]} args = Rest of arguments for executeScripts
237
- * @returns {Promise<Element|Element[]|ImageElement>} - WebDriver element with a special id prefix
221
+ * @param multiple - Whether to lookup multiple elements
222
+ * @param driver - The driver to use for commands
223
+ * @param args - Rest of arguments for executeScripts
224
+ * @returns WebDriver element with a special id prefix
238
225
  */
239
- async find(multiple, driver, ...args) {
226
+ async find(multiple: boolean, driver: ExternalDriver, ...args: any[]): Promise<Element | Element[] | ImageElement> {
240
227
  const [strategy, selector] = args;
241
228
  if (strategy !== IMAGE_STRATEGY) {
242
229
  throw new errors.InvalidSelectorError(`Lookup strategies other than '${IMAGE_STRATEGY}' are not supported`);
243
230
  }
244
- return await (/** @type {import('./finder').default} */ (this.finder)).findByImage(
245
- Buffer.from(selector, 'base64'),
246
- driver,
247
- {multiple, containerRect: this.rect}
248
- );
231
+ if (!this.finder) {
232
+ throw new Error('Finder is not available');
233
+ }
234
+ return await this.finder.findByImage(Buffer.from(selector, 'base64'), driver, {
235
+ multiple,
236
+ containerRect: this.rect,
237
+ });
249
238
  }
250
239
 
251
240
  /**
252
241
  * Handle various Appium commands that involve an image element
253
242
  *
254
- * @param {import('appium/driver').BaseDriver} driver - the driver to use for commands
255
- * @param {string} cmd - the name of the driver command
256
- * @param {any} imgEl - image element object
257
- * @param {string[]} args - Rest of arguments for executeScripts
243
+ * @param driver - the driver to use for commands
244
+ * @param cmd - the name of the driver command
245
+ * @param imgEl - image element object
246
+ * @param args - Rest of arguments for executeScripts
258
247
  *
259
- * @returns {Promise<any>} - the result of running a command
248
+ * @returns the result of running a command
260
249
  */
261
- static async execute(driver, imgEl, cmd, ...args) {
250
+ static async execute(driver: ExternalDriver, imgEl: ImageElement, cmd: string, ...args: any[]): Promise<any> {
262
251
  switch (cmd) {
263
252
  case 'click':
264
253
  return await imgEl.click(driver);
@@ -294,10 +283,3 @@ export default class ImageElement {
294
283
  }
295
284
  }
296
285
  }
297
-
298
- export {ImageElement};
299
-
300
- /**
301
- * @typedef {import('@appium/types').Rect} Rect
302
- * @typedef {import('@appium/types').Element} Element
303
- */
package/lib/index.ts ADDED
@@ -0,0 +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';
package/lib/logger.ts ADDED
@@ -0,0 +1,3 @@
1
+ import {logger} from 'appium/support';
2
+
3
+ export const log = logger.getLogger('ImageElementPlugin');
@@ -3,22 +3,26 @@ import {errors} from 'appium/driver';
3
3
  import {util} from '@appium/support';
4
4
  import {BasePlugin} from 'appium/plugin';
5
5
  import {compareImages} from './compare';
6
- import ImageElementFinder from './finder';
6
+ import {ImageElementFinder} from './finder';
7
7
  import {ImageElement} from './image-element';
8
8
  import {IMAGE_STRATEGY, IMAGE_ELEMENT_PREFIX} from './constants';
9
+ import type {ExternalDriver, Element, ActionSequence, MethodMap} from '@appium/types';
10
+ import type {MatchingOptions, SimilarityOptions, OccurrenceOptions} from '@appium/opencv';
9
11
 
10
- function getImgElFromArgs(args) {
12
+ export function getImgElFromArgs(args: any[]): string | undefined {
11
13
  return args.find((arg) => _.isString(arg) && arg.startsWith(IMAGE_ELEMENT_PREFIX));
12
14
  }
13
15
 
14
- export default class ImageElementPlugin extends BasePlugin {
15
- constructor(pluginName) {
16
+ export class ImageElementPlugin extends BasePlugin {
17
+ readonly finder: ImageElementFinder;
18
+
19
+ constructor(pluginName: string) {
16
20
  super(pluginName);
17
21
  this.finder = new ImageElementFinder();
18
22
  }
19
23
 
20
24
  // this plugin supports a non-standard 'compare images' command
21
- static newMethodMap = /** @type {const} */ ({
25
+ static newMethodMap: MethodMap<ImageElementPlugin> = {
22
26
  '/session/:sessionId/appium/compare_images': {
23
27
  POST: {
24
28
  command: 'compareImages',
@@ -29,30 +33,33 @@ export default class ImageElementPlugin extends BasePlugin {
29
33
  neverProxy: true,
30
34
  },
31
35
  },
32
- });
33
-
34
- async compareImages(next, driver, ...args) {
35
- // @ts-ignore Arguments should be ok there
36
- return await compareImages(...args);
36
+ } as const;
37
+
38
+ async compareImages(
39
+ next: () => Promise<any>,
40
+ driver: ExternalDriver,
41
+ mode: string,
42
+ firstImage: string | Buffer,
43
+ secondImage: string | Buffer,
44
+ options?: MatchingOptions | SimilarityOptions | OccurrenceOptions
45
+ ): Promise<any> {
46
+ return await compareImages(mode, firstImage, secondImage, options);
37
47
  }
38
48
 
39
- async findElement(next, driver, ...args) {
49
+ async findElement(next: () => Promise<any>, driver: ExternalDriver, ...args: any[]): Promise<any> {
40
50
  return await this._find(false, next, driver, ...args);
41
51
  }
42
52
 
43
- async findElements(next, driver, ...args) {
53
+ async findElements(next: () => Promise<any>, driver: ExternalDriver, ...args: any[]): Promise<any> {
44
54
  return await this._find(true, next, driver, ...args);
45
55
  }
46
56
 
47
- /**
48
- *
49
- * @param {boolean} multiple
50
- * @param {*} next
51
- * @param {*} driver
52
- * @param {...any} args
53
- * @returns {Promise<any>}
54
- */
55
- async _find(multiple, next, driver, ...args) {
57
+ private async _find(
58
+ multiple: boolean,
59
+ next: () => Promise<any>,
60
+ driver: ExternalDriver,
61
+ ...args: any[]
62
+ ): Promise<any> {
56
63
  const [strategy, selector] = args;
57
64
 
58
65
  // if we're not actually finding by image, just do the normal thing
@@ -63,7 +70,12 @@ export default class ImageElementPlugin extends BasePlugin {
63
70
  return await this.finder.findByImage(Buffer.from(selector, 'base64'), driver, {multiple});
64
71
  }
65
72
 
66
- async handle(next, driver, cmdName, ...args) {
73
+ async handle(
74
+ next: () => Promise<any>,
75
+ driver: ExternalDriver,
76
+ cmdName: string,
77
+ ...args: any[]
78
+ ): Promise<any> {
67
79
  // if we have a command that involves an image element id, attempt to find the image element
68
80
  // and execute the command on it
69
81
  const imgElId = getImgElFromArgs(args);
@@ -83,28 +95,22 @@ export default class ImageElementPlugin extends BasePlugin {
83
95
  return await next();
84
96
  }
85
97
 
86
- async performActions(next, driver, ...args) {
98
+ async performActions(
99
+ next: () => Promise<any>,
100
+ driver: ExternalDriver,
101
+ actionSequences: ActionSequence[]
102
+ ): Promise<any> {
87
103
  // Replace with coordinates when ActionSequence includes image elements.
88
- const [actionSequences] = /** @type {[import('@appium/types').ActionSequence[]]} */ (args);
89
104
  for (const actionSequence of actionSequences) {
90
105
  for (const action of actionSequence.actions) {
91
106
  // The actions that can have an Element as the origin are "pointerMove" and "scroll".
92
- if (
93
- !_.isPlainObject(
94
- /** @type {{origin?: "viewport" | "pointer" | import('@appium/types').Element}} */ (
95
- action
96
- ).origin,
97
- )
98
- ) {
107
+ if (!_.isPlainObject((action as any).origin)) {
99
108
  continue;
100
109
  }
101
110
 
102
- const actionWithEl =
103
- /** @type {import('@appium/types').PointerMoveAction | import('@appium/types').ScrollAction} */ (
104
- action
105
- );
111
+ const actionWithEl = action as any;
106
112
 
107
- const elId = util.unwrapElement(/** @type {import('@appium/types').Element} */ (actionWithEl.origin));
113
+ const elId = util.unwrapElement(actionWithEl.origin as Element);
108
114
  if (!_.startsWith(elId, IMAGE_ELEMENT_PREFIX)) {
109
115
  continue;
110
116
  }
@@ -125,5 +131,3 @@ export default class ImageElementPlugin extends BasePlugin {
125
131
  return await next();
126
132
  }
127
133
  }
128
-
129
- export {ImageElementPlugin, getImgElFromArgs, IMAGE_STRATEGY};
package/lib/types.ts ADDED
@@ -0,0 +1,187 @@
1
+ import type {Rect} from '@appium/types';
2
+ import type {ImageElementFinder} from './finder';
3
+ import type {MatchingResult, OccurrenceResult, SimilarityResult} from '@appium/opencv';
4
+ import {
5
+ IMAGE_EL_TAP_STRATEGY_W3C,
6
+ IMAGE_EL_TAP_STRATEGY_MJSONWP,
7
+ } from './constants';
8
+
9
+ /**
10
+ * Image settings interface for device settings
11
+ */
12
+ export interface ImageSettings {
13
+ // value between 0 and 1 representing match strength, below which an image
14
+ // element will not be found
15
+ imageMatchThreshold: number;
16
+
17
+ // One of possible image matching methods.
18
+ // Read https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html
19
+ // for more details.
20
+ // TM_CCOEFF_NORMED by default
21
+ imageMatchMethod: string;
22
+
23
+ // if the image returned by getScreenshot differs in size or aspect ratio
24
+ // from the screen, attempt to fix it automatically
25
+ fixImageFindScreenshotDims: boolean;
26
+
27
+ // whether Appium should ensure that an image template sent in during image
28
+ // element find should have its size adjusted so the match algorithm will not
29
+ // complain
30
+ fixImageTemplateSize: boolean;
31
+
32
+ // whether Appium should ensure that an image template sent in during image
33
+ // element find should have its scale adjusted to display size so the match
34
+ // algorithm will not complain.
35
+ // e.g. iOS has `width=375, height=667` window rect, but its screenshot is
36
+ // `width=750 × height=1334` pixels. This setting help to adjust the scale
37
+ // if a user use `width=750 × height=1334` pixels's base template image.
38
+ fixImageTemplateScale: boolean;
39
+
40
+ // Users might have scaled template image to reduce their storage size.
41
+ // This setting allows users to scale a template image they send to Appium server
42
+ // so that the Appium server compares the actual scale users originally had.
43
+ // e.g. If a user has an image of 270 x 32 pixels which was originally 1080 x 126 pixels,
44
+ // the user can set {defaultImageTemplateScale: 4.0} to scale the small image
45
+ // to the original one so that Appium can compare it as the original one.
46
+ defaultImageTemplateScale: number;
47
+
48
+ // whether Appium should re-check that an image element can be matched
49
+ // against the current screenshot before clicking it
50
+ checkForImageElementStaleness: boolean;
51
+
52
+ // whether before clicking on an image element Appium should re-determine the
53
+ // position of the element on screen
54
+ autoUpdateImageElementPosition: boolean;
55
+
56
+ // which method to use for tapping by coordinate for image elements. the
57
+ // options are 'w3c' or 'mjsonwp'
58
+ imageElementTapStrategy: typeof IMAGE_EL_TAP_STRATEGY_W3C | typeof IMAGE_EL_TAP_STRATEGY_MJSONWP;
59
+
60
+ // which method to use to save the matched image area in ImageElement class.
61
+ // It is used for debugging purpose.
62
+ getMatchedImageResult: boolean;
63
+ }
64
+
65
+ /**
66
+ * Options for finding elements by image
67
+ */
68
+ export interface FindByImageOptions {
69
+ /** whether this call to find an image is merely to check staleness.
70
+ * If so we can bypass a lot of logic */
71
+ shouldCheckStaleness?: boolean;
72
+ /** Whether we are finding one element or multiple */
73
+ multiple?: boolean;
74
+ /** Whether we ignore defaultImageTemplateScale. It can be used when you would like to
75
+ * scale template with defaultImageTemplateScale setting. */
76
+ ignoreDefaultImageTemplateScale?: boolean;
77
+ /** The bounding rectangle to limit the search in */
78
+ containerRect?: Rect | null;
79
+ }
80
+
81
+ /**
82
+ * Options for creating an ImageElement
83
+ */
84
+ export interface ImageElementOpts {
85
+ /** the image which was used to find this ImageElement */
86
+ template: Buffer;
87
+ /** bounds of matched image element */
88
+ rect: Rect;
89
+ /** The similarity score as a float number in range [0.0, 1.0]. 1.0 is the highest
90
+ * score (means both images are totally equal). */
91
+ score: number;
92
+ /** the image which has matched marks. Defaults to null. */
93
+ match?: Buffer | null;
94
+ /** the finder we can use to re-check stale elements */
95
+ finder?: ImageElementFinder | null;
96
+ /** The bounding rectangle to limit the search in */
97
+ containerRect?: Rect | null;
98
+ }
99
+
100
+ /**
101
+ * Dimension interface for width and height
102
+ */
103
+ export interface Dimension {
104
+ width: number;
105
+ height: number;
106
+ }
107
+
108
+ /**
109
+ * Position interface for x and y coordinates
110
+ */
111
+ export interface Position {
112
+ x: number;
113
+ y: number;
114
+ }
115
+
116
+ /**
117
+ * Screenshot interface
118
+ */
119
+ export interface Screenshot {
120
+ screenshot: Buffer;
121
+ }
122
+
123
+ /**
124
+ * Screenshot scale interface
125
+ */
126
+ export interface ScreenshotScale {
127
+ xScale: number;
128
+ yScale: number;
129
+ }
130
+
131
+ /**
132
+ * Image template settings for scaling
133
+ */
134
+ export interface ImageTemplateSettings {
135
+ /** fixImageTemplateScale in device-settings */
136
+ fixImageTemplateScale?: boolean;
137
+ /** defaultImageTemplateScale in device-settings */
138
+ defaultImageTemplateScale?: number;
139
+ /** Ignore defaultImageTemplateScale if it has true. If the template
140
+ * has been scaled to defaultImageTemplateScale or should ignore the scale,
141
+ * this parameter should be true. e.g. click in image-element module */
142
+ ignoreDefaultImageTemplateScale?: boolean;
143
+ /** Scale ratio for width */
144
+ xScale?: number;
145
+ /** Scale ratio for height */
146
+ yScale?: number;
147
+ }
148
+
149
+ /**
150
+ * Occurrence result with visualization (string instead of Buffer)
151
+ */
152
+ export interface OccurrenceResultWithVisualization {
153
+ rect: Rect;
154
+ score: number;
155
+ visualization?: string | null;
156
+ }
157
+
158
+ /**
159
+ * Interface for results with string visualization instead of Buffer
160
+ */
161
+ export interface Visualized {
162
+ visualization?: string | null;
163
+ }
164
+
165
+ /**
166
+ * Matching result with string visualization
167
+ */
168
+ export type VisualizedMatchingResult = MatchingResult & Visualized;
169
+
170
+ /**
171
+ * Occurrence result with string visualization
172
+ */
173
+ export type VisualizedOccurrenceResult = OccurrenceResult & Visualized;
174
+
175
+ /**
176
+ * Similarity result with string visualization
177
+ */
178
+ export type VisualizedSimilarityResult = SimilarityResult & Visualized;
179
+
180
+ /**
181
+ * Result type for image comparison operations
182
+ */
183
+ export type ComparisonResult =
184
+ | VisualizedMatchingResult
185
+ | VisualizedOccurrenceResult
186
+ | VisualizedSimilarityResult
187
+ | VisualizedSimilarityResult[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/images-plugin",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Plugin for working with images and image elements in Appium",
5
5
  "keywords": [
6
6
  "automation",
@@ -23,28 +23,28 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "author": "https://github.com/appium",
26
- "types": "./build/lib/plugin.d.ts",
26
+ "main": "./build/lib/index.js",
27
+ "types": "./build/lib/index.d.ts",
27
28
  "files": [
28
29
  "build",
29
30
  "docs",
30
31
  "lib",
31
- "index.js",
32
32
  "tsconfig.json",
33
- "!build/tsconfig.tsbuildinfo"
33
+ "!build/tsconfig.tsbuildinfo",
34
+ "!build/test"
34
35
  ],
35
36
  "scripts": {
36
37
  "test": "npm run test:unit",
37
- "test:e2e": "mocha --exit --timeout 40s --slow 20s \"./test/e2e/**/*.spec.*js\"",
38
- "test:smoke": "node ./index.js",
39
- "test:unit": "mocha \"./test/unit/**/*.spec.*js\""
38
+ "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\""
40
41
  },
41
42
  "dependencies": {
42
- "@appium/opencv": "^4.0.3",
43
- "@appium/support": "^7.0.4",
44
- "lodash": "4.17.21",
45
- "lru-cache": "11.2.4",
46
- "sharp": "0.34.5",
47
- "source-map-support": "0.5.21"
43
+ "@appium/opencv": "^4.1.0",
44
+ "@appium/support": "^7.0.5",
45
+ "lodash": "4.17.23",
46
+ "lru-cache": "11.2.5",
47
+ "sharp": "0.34.5"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "appium": "^3.0.0-beta.0"
@@ -60,5 +60,5 @@
60
60
  "publishConfig": {
61
61
  "access": "public"
62
62
  },
63
- "gitHead": "9004554879687ddad51d3afdf8c711b027efbd99"
63
+ "gitHead": "f7b20335eab4022e5cbbb627ec86866a994444f8"
64
64
  }
package/tsconfig.json CHANGED
@@ -6,10 +6,11 @@
6
6
  "strict": false,
7
7
  "paths": {
8
8
  "@appium/opencv": ["../opencv"]
9
- }
9
+ },
10
+ "types": ["mocha", "chai", "sinon", "chai-as-promised"]
10
11
  },
11
12
  "extends": "@appium/tsconfig/tsconfig.plugin.json",
12
- "include": ["lib"],
13
+ "include": ["lib", "test"],
13
14
  "references": [
14
15
  {
15
16
  "path": "../opencv"