@appium/images-plugin 2.0.10 → 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.
@@ -8,6 +8,17 @@
8
8
  * @property {number} x - x coordinate
9
9
  * @property {number} y - y coordinate
10
10
  */
11
+ /**
12
+ * @typedef ImageElementOpts
13
+ * @property {Buffer} template - the image which was used to find this ImageElement
14
+ * @property {Rect} rect - bounds of matched image element
15
+ * @property {number} score The similarity score as a float number in range [0.0, 1.0].
16
+ * 1.0 is the highest score (means both images are totally equal).
17
+ * @property {Buffer?} match - the image which has matched marks. Defaults to null.
18
+ * @property {import('./finder').default?} finder - the finder we can use to re-check stale elements
19
+ * @property {import('@appium/types').Rect?} containerRect - The bounding
20
+ * rectangle to limit the search in
21
+ */
11
22
  /**
12
23
  * Representation of an "image element", which is simply a set of coordinates
13
24
  * and methods that can be used on that set of coordinates via the driver
@@ -23,24 +34,18 @@ export default class ImageElement {
23
34
  *
24
35
  * @returns {object} - the result of running a command
25
36
  */
26
- static execute(driver: import("appium/driver").BaseDriver<any, import("@appium/types").StringRecord<any>, import("@appium/types").StringRecord<any>>, imgEl: any, cmd: string, ...args: string[]): object;
37
+ static execute(driver: import("appium/driver").BaseDriver<any, import("@appium/types").StringRecord<any>, import("@appium/types").StringRecord<any>, import("@appium/types").StringRecord<any>>, imgEl: any, cmd: string, ...args: string[]): object;
27
38
  /**
28
- * @param {string} b64Template - the base64-encoded image which was used to
29
- * find this ImageElement
30
- * @param {Rect} rect - bounds of matched image element
31
- * @param {number} score The similarity score as a float number in range [0.0, 1.0].
32
- * 1.0 is the highest score (means both images are totally equal).
33
- * @param {string?} b64Result - the base64-encoded image which has matched marks.
34
- * Defaults to null.
35
- * @param {import('./finder').default?} finder - the finder we can use to re-check stale elements
39
+ * @param {ImageElementOpts}
36
40
  */
37
- constructor(b64Template: string, rect: Rect, score: number, b64Result?: string | null, finder?: import('./finder').default | null);
38
- template: string;
41
+ constructor({ template, rect, score, match, finder, containerRect, }: ImageElementOpts);
42
+ template: Buffer;
39
43
  rect: import("@appium/types").Rect;
40
44
  id: string;
41
- b64MatchedImage: string | null;
45
+ match: Buffer | null;
42
46
  score: number;
43
47
  finder: import("./finder").default | null;
48
+ containerRect: import("@appium/types").Rect | null;
44
49
  /**
45
50
  * @returns {Dimension} - dimension of element
46
51
  */
@@ -54,16 +59,18 @@ export default class ImageElement {
54
59
  */
55
60
  get center(): Position;
56
61
  /**
57
- * @returns {?string} - the base64-encoded image which has matched marks
62
+ * @returns {string} - the base64-encoded original image used for matching
63
+ */
64
+ get originalImage(): string;
65
+ /**
66
+ * @returns {string|null} - the base64-encoded image which has matched marks
58
67
  */
59
68
  get matchedImage(): string | null;
60
69
  /**
61
- * @param {string} protocolKey - the protocol-specific JSON key for
62
- * a WebElement
63
70
  *
64
71
  * @returns {Element} - this image element as a WebElement
65
72
  */
66
- asElement(protocolKey: string): Element;
73
+ asElement(): Element;
67
74
  /**
68
75
  * @param {ImageElement} other - an ImageElement to compare with this one
69
76
  *
@@ -78,6 +85,15 @@ export default class ImageElement {
78
85
  * @param {BaseDriver} driver - driver for calling actions with
79
86
  */
80
87
  click(driver: BaseDriver): Promise<any>;
88
+ /**
89
+ * Perform lookup of image element(s) inside of the current element
90
+ *
91
+ * @param {boolean} multiple - Whether to lookup multiple elements
92
+ * @param {import('appium/driver').BaseDriver} driver - The driver to use for commands
93
+ * @param {string[]} args = Rest of arguments for executeScripts
94
+ * @returns {Promise<Element|Element[]|ImageElement>} - WebDriver element with a special id prefix
95
+ */
96
+ find(multiple: boolean, driver: import("appium/driver").BaseDriver<any, import("@appium/types").StringRecord<any>, import("@appium/types").StringRecord<any>, import("@appium/types").StringRecord<any>>, ...args: string[]): Promise<Element | Element[] | ImageElement>;
81
97
  }
82
98
  export type Dimension = {
83
99
  /**
@@ -99,10 +115,34 @@ export type Position = {
99
115
  */
100
116
  y: number;
101
117
  };
118
+ export type ImageElementOpts = {
119
+ /**
120
+ * - the image which was used to find this ImageElement
121
+ */
122
+ template: Buffer;
123
+ /**
124
+ * - bounds of matched image element
125
+ */
126
+ rect: Rect;
127
+ /**
128
+ * The similarity score as a float number in range [0.0, 1.0].
129
+ * 1.0 is the highest score (means both images are totally equal).
130
+ */
131
+ score: number;
132
+ /**
133
+ * - the image which has matched marks. Defaults to null.
134
+ */
135
+ match: Buffer | null;
136
+ /**
137
+ * - the finder we can use to re-check stale elements
138
+ */
139
+ finder: import('./finder').default | null;
140
+ /**
141
+ * - The bounding
142
+ * rectangle to limit the search in
143
+ */
144
+ containerRect: import('@appium/types').Rect | null;
145
+ };
102
146
  export type Rect = import('@appium/types').Rect;
103
147
  export type Element = import('@appium/types').Element;
104
- export const IMAGE_EL_TAP_STRATEGY_MJSONWP: "touchActions";
105
- export const IMAGE_EL_TAP_STRATEGY_W3C: "w3cActions";
106
- export const DEFAULT_TEMPLATE_IMAGE_SCALE: 1;
107
- export const IMAGE_ELEMENT_PREFIX: "appium-image-element-";
108
148
  //# sourceMappingURL=image-element.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-element.d.ts","sourceRoot":"","sources":["../../lib/image-element.js"],"names":[],"mappings":"AAaA;;;;GAIG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH;IAsLE;;;;;;;;;OASG;IACH,uKANW,MAAM,WAEN,MAAM,EAAE,GAEN,MAAM,CA8BlB;IA3ND;;;;;;;;;OASG;IACH,yBATW,MAAM,QAEN,IAAI,SACJ,MAAM,cAEN,MAAM,kBAEN,OAAO,UAAU,EAAE,OAAO,SASpC;IANC,iBAA2B;IAC3B,mCAAgB;IAChB,WAAmD;IACnD,+BAAgC;IAChC,cAAkB;IAClB,0CAAoB;IAGtB;;OAEG;IACH,sBAEC;IAED;;OAEG;IACH,yBAEC;IAED;;OAEG;IACH,uBAKC;IAED;;OAEG;IACH,kCAEC;IAED;;;;;OAKG;IACH,uBALW,MAAM,GAGJ,OAAO,CAInB;IAED;;;;;OAKG;IACH,cALW,YAAY,GAEV,OAAO,CAUnB;IAED;;;;;OAKG;IACH,wCAkGC;CAyCF;;;;;WA3Oa,MAAM;;;;YACN,MAAM;;;;;;OAKN,MAAM;;;;OACN,MAAM;;mBA+OP,OAAO,eAAe,EAAE,IAAI;sBAC5B,OAAO,eAAe,EAAE,OAAO;AA7P5C,2DAAqD;AADrD,qDAA+C;AAG/C,6CAAyC;AALzC,2DAAqD"}
1
+ {"version":3,"file":"image-element.d.ts","sourceRoot":"","sources":["../../lib/image-element.js"],"names":[],"mappings":"AAWA;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AAEH;;;GAGG;AACH;IA6ME;;;;;;;;;OASG;IACH,kNANW,MAAM,WAEN,MAAM,EAAE,GAEN,MAAM,CAoClB;IAxPD;;OAEG;IACH,sEAFW,gBAAgB,EAiB1B;IAPC,iBAAwB;IACxB,mCAAgB;IAChB,WAAmD;IACnD,qBAAkB;IAClB,cAAkB;IAClB,0CAAoB;IACpB,mDAAkC;IAGpC;;OAEG;IACH,sBAEC;IAED;;OAEG;IACH,yBAEC;IAED;;OAEG;IACH,uBAKC;IAED;;OAEG;IACH,4BAEC;IAED;;OAEG;IACH,kCAEC;IAED;;;OAGG;IACH,aAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,cALW,YAAY,GAEV,OAAO,CAUnB;IAED;;;;;OAKG;IACH,wCAmGC;IAED;;;;;;;OAOG;IACH,eALW,OAAO,6LAEN,MAAM,EAAE,GACP,QAAQ,OAAO,GAAC,OAAO,EAAE,GAAC,YAAY,CAAC,CAQnD;CA+CF;;;;;WApRa,MAAM;;;;YACN,MAAM;;;;;;OAKN,MAAM;;;;OACN,MAAM;;;;;;cAKN,MAAM;;;;UACN,IAAI;;;;;WACJ,MAAM;;;;WAEN,MAAM;;;;YACN,OAAO,UAAU,EAAE,OAAO;;;;;mBAC1B,OAAO,eAAe,EAAE,IAAI;;mBAuQ7B,OAAO,eAAe,EAAE,IAAI;sBAC5B,OAAO,eAAe,EAAE,OAAO"}
@@ -3,22 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IMAGE_ELEMENT_PREFIX = exports.DEFAULT_TEMPLATE_IMAGE_SCALE = exports.IMAGE_EL_TAP_STRATEGY_W3C = exports.IMAGE_EL_TAP_STRATEGY_MJSONWP = exports.ImageElement = void 0;
6
+ exports.ImageElement = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const driver_1 = require("appium/driver");
9
9
  const support_1 = require("appium/support");
10
10
  const logger_1 = __importDefault(require("./logger"));
11
- const finder_1 = require("./finder");
12
- const IMAGE_ELEMENT_PREFIX = 'appium-image-element-';
13
- exports.IMAGE_ELEMENT_PREFIX = IMAGE_ELEMENT_PREFIX;
11
+ const constants_1 = require("./constants");
14
12
  const TAP_DURATION_MS = 125;
15
- const IMAGE_EL_TAP_STRATEGY_W3C = 'w3cActions';
16
- exports.IMAGE_EL_TAP_STRATEGY_W3C = IMAGE_EL_TAP_STRATEGY_W3C;
17
- const IMAGE_EL_TAP_STRATEGY_MJSONWP = 'touchActions';
18
- exports.IMAGE_EL_TAP_STRATEGY_MJSONWP = IMAGE_EL_TAP_STRATEGY_MJSONWP;
19
- const IMAGE_TAP_STRATEGIES = [IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C];
20
- const DEFAULT_TEMPLATE_IMAGE_SCALE = 1.0;
21
- exports.DEFAULT_TEMPLATE_IMAGE_SCALE = DEFAULT_TEMPLATE_IMAGE_SCALE;
22
13
  /**
23
14
  * @typedef Dimension
24
15
  * @property {number} width - width of rect
@@ -29,28 +20,33 @@ exports.DEFAULT_TEMPLATE_IMAGE_SCALE = DEFAULT_TEMPLATE_IMAGE_SCALE;
29
20
  * @property {number} x - x coordinate
30
21
  * @property {number} y - y coordinate
31
22
  */
23
+ /**
24
+ * @typedef ImageElementOpts
25
+ * @property {Buffer} template - the image which was used to find this ImageElement
26
+ * @property {Rect} rect - bounds of matched image element
27
+ * @property {number} score The similarity score as a float number in range [0.0, 1.0].
28
+ * 1.0 is the highest score (means both images are totally equal).
29
+ * @property {Buffer?} match - the image which has matched marks. Defaults to null.
30
+ * @property {import('./finder').default?} finder - the finder we can use to re-check stale elements
31
+ * @property {import('@appium/types').Rect?} containerRect - The bounding
32
+ * rectangle to limit the search in
33
+ */
32
34
  /**
33
35
  * Representation of an "image element", which is simply a set of coordinates
34
36
  * and methods that can be used on that set of coordinates via the driver
35
37
  */
36
38
  class ImageElement {
37
39
  /**
38
- * @param {string} b64Template - the base64-encoded image which was used to
39
- * find this ImageElement
40
- * @param {Rect} rect - bounds of matched image element
41
- * @param {number} score The similarity score as a float number in range [0.0, 1.0].
42
- * 1.0 is the highest score (means both images are totally equal).
43
- * @param {string?} b64Result - the base64-encoded image which has matched marks.
44
- * Defaults to null.
45
- * @param {import('./finder').default?} finder - the finder we can use to re-check stale elements
40
+ * @param {ImageElementOpts}
46
41
  */
47
- constructor(b64Template, rect, score, b64Result = null, finder = null) {
48
- this.template = b64Template;
42
+ constructor({ template, rect, score, match = null, finder = null, containerRect = null, }) {
43
+ this.template = template;
49
44
  this.rect = rect;
50
- this.id = `${IMAGE_ELEMENT_PREFIX}${support_1.util.uuidV4()}`;
51
- this.b64MatchedImage = b64Result;
45
+ this.id = `${constants_1.IMAGE_ELEMENT_PREFIX}${support_1.util.uuidV4()}`;
46
+ this.match = match;
52
47
  this.score = score;
53
48
  this.finder = finder;
49
+ this.containerRect = containerRect;
54
50
  }
55
51
  /**
56
52
  * @returns {Dimension} - dimension of element
@@ -74,19 +70,23 @@ class ImageElement {
74
70
  };
75
71
  }
76
72
  /**
77
- * @returns {?string} - the base64-encoded image which has matched marks
73
+ * @returns {string} - the base64-encoded original image used for matching
74
+ */
75
+ get originalImage() {
76
+ return this.template.toString('base64');
77
+ }
78
+ /**
79
+ * @returns {string|null} - the base64-encoded image which has matched marks
78
80
  */
79
81
  get matchedImage() {
80
- return this.b64MatchedImage;
82
+ return this.match?.toString('base64') ?? null;
81
83
  }
82
84
  /**
83
- * @param {string} protocolKey - the protocol-specific JSON key for
84
- * a WebElement
85
85
  *
86
86
  * @returns {Element} - this image element as a WebElement
87
87
  */
88
- asElement(protocolKey) {
89
- return { [protocolKey]: this.id };
88
+ asElement() {
89
+ return support_1.util.wrapElement(this.id);
90
90
  }
91
91
  /**
92
92
  * @param {ImageElement} other - an ImageElement to compare with this one
@@ -110,22 +110,23 @@ class ImageElement {
110
110
  // before we click we need to make sure the element is actually still there
111
111
  // where we expect it to be
112
112
  let newImgEl;
113
- const settings = Object.assign({}, finder_1.DEFAULT_SETTINGS, driver.settings.getSettings());
113
+ const settings = Object.assign({}, constants_1.DEFAULT_SETTINGS, driver.settings.getSettings());
114
114
  const { autoUpdateImageElementPosition: updatePos, checkForImageElementStaleness, imageElementTapStrategy, } = settings;
115
115
  // validate tap strategy
116
- if (!IMAGE_TAP_STRATEGIES.includes(imageElementTapStrategy)) {
116
+ if (!constants_1.IMAGE_TAP_STRATEGIES.includes(imageElementTapStrategy)) {
117
117
  throw new Error(`Incorrect imageElementTapStrategy setting ` +
118
118
  `'${imageElementTapStrategy}'. Must be one of ` +
119
- JSON.stringify(IMAGE_TAP_STRATEGIES));
119
+ JSON.stringify(constants_1.IMAGE_TAP_STRATEGIES));
120
120
  }
121
121
  if (checkForImageElementStaleness || updatePos) {
122
122
  logger_1.default.info('Checking image element for staleness before clicking');
123
123
  try {
124
- newImgEl = await this.finder.findByImage(this.template, {
124
+ newImgEl = await this.finder.findByImage(this.template, driver, {
125
125
  shouldCheckStaleness: true,
126
126
  // Set ignoreDefaultImageTemplateScale because this.template is device screenshot based image
127
127
  // managed inside Appium after finidng image by template which managed by a user
128
128
  ignoreDefaultImageTemplateScale: true,
129
+ containerRect: this.containerRect,
129
130
  });
130
131
  }
131
132
  catch (err) {
@@ -150,7 +151,7 @@ class ImageElement {
150
151
  }
151
152
  const { x, y } = this.center;
152
153
  logger_1.default.info(`Will tap on image element at coordinate [${x}, ${y}]`);
153
- if (imageElementTapStrategy === IMAGE_EL_TAP_STRATEGY_W3C) {
154
+ if (imageElementTapStrategy === constants_1.IMAGE_EL_TAP_STRATEGY_W3C) {
154
155
  // set up a W3C action to click on the image by position
155
156
  logger_1.default.info('Will tap using W3C actions');
156
157
  const action = {
@@ -185,6 +186,21 @@ class ImageElement {
185
186
  'For drivers to support finding image elements, they ' +
186
187
  "should support 'performTouch' and 'performActions'");
187
188
  }
189
+ /**
190
+ * Perform lookup of image element(s) inside of the current element
191
+ *
192
+ * @param {boolean} multiple - Whether to lookup multiple elements
193
+ * @param {import('appium/driver').BaseDriver} driver - The driver to use for commands
194
+ * @param {string[]} args = Rest of arguments for executeScripts
195
+ * @returns {Promise<Element|Element[]|ImageElement>} - WebDriver element with a special id prefix
196
+ */
197
+ async find(multiple, driver, ...args) {
198
+ const [strategy, selector] = args;
199
+ if (strategy !== constants_1.IMAGE_STRATEGY) {
200
+ throw new driver_1.errors.InvalidSelectorError(`Lookup strategies other than '${constants_1.IMAGE_STRATEGY}' are not supported`);
201
+ }
202
+ return await this.finder.findByImage(selector, driver, { multiple, containerRect: this.rect });
203
+ }
188
204
  /**
189
205
  * Handle various Appium commands that involve an image element
190
206
  *
@@ -199,6 +215,10 @@ class ImageElement {
199
215
  switch (cmd) {
200
216
  case 'click':
201
217
  return await imgEl.click(driver);
218
+ case 'findElementFromElement':
219
+ return await imgEl.find(false, driver, ...args);
220
+ case 'findElementsFromElement':
221
+ return await imgEl.find(true, driver, ...args);
202
222
  case 'elementDisplayed':
203
223
  return true;
204
224
  case 'getSize':
@@ -208,6 +228,8 @@ class ImageElement {
208
228
  return imgEl.location;
209
229
  case 'getElementRect':
210
230
  return imgEl.rect;
231
+ case 'getElementScreenshot':
232
+ return imgEl.originalImage;
211
233
  case 'getAttribute':
212
234
  // /session/:sessionId/element/:elementId/attribute/:name
213
235
  // /session/:sessionId/element/:elementId/attribute/visual should retun the visual data
@@ -1 +1 @@
1
- {"version":3,"file":"image-element.js","sourceRoot":"","sources":["../../lib/image-element.js"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,0CAAqC;AACrC,4CAAoC;AACpC,sDAA2B;AAC3B,qCAA0C;AAE1C,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AA2PnD,oDAAoB;AA1PtB,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,yBAAyB,GAAG,YAAY,CAAC;AAuP7C,8DAAyB;AAtP3B,MAAM,6BAA6B,GAAG,cAAc,CAAC;AAqPnD,sEAA6B;AApP/B,MAAM,oBAAoB,GAAG,CAAC,6BAA6B,EAAE,yBAAyB,CAAC,CAAC;AACxF,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAqPvC,oEAA4B;AAnP9B;;;;GAIG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH,MAAqB,YAAY;IAC/B;;;;;;;;;OASG;IACH,YAAY,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI;QACnE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,GAAG,oBAAoB,GAAG,cAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,EAAC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cmdName: any, ...args: any[]): Promise<any>;
21
21
  }
22
22
  import ImageElementFinder from "./finder";
23
- export function getImgElFromArgs(args: any): string | undefined;
24
- export const IMAGE_STRATEGY: "-image";
23
+ export function getImgElFromArgs(args: any): any;
24
+ import { IMAGE_STRATEGY } from "./constants";
25
+ export { IMAGE_STRATEGY };
25
26
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.js"],"names":[],"mappings":"AAmBA;IAOE;;;;;;;;;;;MAWG;IAjBH,6BAGC;IADC,2BAAsC;IAiBxC,wEAEC;IAED,kEAEC;IAED,mEAEC;IAED,2EAUC;IAED,2EAcC;CACF;;AAnED,gEAMC;AARD,sCAAgC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.js"],"names":[],"mappings":"AAcA;IAOE;;;;;;;;;;;MAWG;IAjBH,6BAGC;IADC,2BAAsC;IAiBxC,wEAEC;IAED,kEAEC;IAED,mEAEC;IAED,2EASC;IAED,2EAkBC;CACF;;AAlED,iDAEC"}
@@ -11,14 +11,10 @@ const plugin_1 = __importDefault(require("appium/plugin"));
11
11
  const compare_1 = require("./compare");
12
12
  const finder_1 = __importDefault(require("./finder"));
13
13
  const image_element_1 = require("./image-element");
14
- const IMAGE_STRATEGY = '-image';
15
- exports.IMAGE_STRATEGY = IMAGE_STRATEGY;
14
+ const constants_1 = require("./constants");
15
+ Object.defineProperty(exports, "IMAGE_STRATEGY", { enumerable: true, get: function () { return constants_1.IMAGE_STRATEGY; } });
16
16
  function getImgElFromArgs(args) {
17
- for (let arg of args) {
18
- if (lodash_1.default.isString(arg) && arg.startsWith(image_element_1.IMAGE_ELEMENT_PREFIX)) {
19
- return arg;
20
- }
21
- }
17
+ return args.find((arg) => lodash_1.default.isString(arg) && arg.startsWith(constants_1.IMAGE_ELEMENT_PREFIX));
22
18
  }
23
19
  exports.getImgElFromArgs = getImgElFromArgs;
24
20
  class ImageElementPlugin extends plugin_1.default {
@@ -38,23 +34,25 @@ class ImageElementPlugin extends plugin_1.default {
38
34
  async _find(multiple, next, driver, ...args) {
39
35
  const [strategy, selector] = args;
40
36
  // if we're not actually finding by image, just do the normal thing
41
- if (strategy !== IMAGE_STRATEGY) {
37
+ if (strategy !== constants_1.IMAGE_STRATEGY) {
42
38
  return await next();
43
39
  }
44
- this.finder.setDriver(driver);
45
- return await this.finder.findByImage(selector, { multiple });
40
+ return await this.finder.findByImage(selector, driver, { multiple });
46
41
  }
47
42
  async handle(next, driver, cmdName, ...args) {
48
43
  // if we have a command that involves an image element id, attempt to find the image element
49
44
  // and execute the command on it
50
45
  const imgElId = getImgElFromArgs(args);
51
46
  if (imgElId) {
52
- if (!this.finder.imgElCache.has(imgElId)) {
47
+ const imgEl = this.finder.getImageElement(imgElId);
48
+ if (!imgEl) {
53
49
  throw new driver_1.errors.NoSuchElementError();
54
50
  }
55
- const imgEl = this.finder.imgElCache.get(imgElId);
56
51
  return await image_element_1.ImageElement.execute(driver, imgEl, cmdName, ...args);
57
52
  }
53
+ if (cmdName === 'deleteSession') {
54
+ this.finder.clearImageElements();
55
+ }
58
56
  // otherwise just do the normal thing
59
57
  return await next();
60
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.js"],"names":[],"mappings":";AAAA,yCAAyC;;;;;;AAEzC,oDAAuB;AACvB,0CAAqC;AACrC,2DAAuC;AACvC,uCAAwC;AACxC,sDAA0C;AAC1C,mDAAmE;AAEnE,MAAM,cAAc,GAAG,QAAQ,CAAC;AAuEc,wCAAc;AArE5D,SAAS,gBAAgB,CAAC,IAAI;IAC5B,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;QACpB,IAAI,gBAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,oCAAoB,CAAC,EAAE;YAC3D,OAAO,GAAG,CAAC;SACZ;KACF;AACH,C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AAC,eAAe,CAAC,OAAO,CAAC,CAAC;YACnD,IAAI,CAAC,KAAK,EAAE;gBACV,MAAM,IAAI,eAAM,CAAC,kBAAkB,EAAE,CAAC;aACvC;YACD,OAAO,MAAM,4BAAY,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;SACpE;QAED,IAAI,OAAO,KAAK,eAAe,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;SAClC;QAED,qCAAqC;QACrC,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;;AA7DH,qCA8DC;AAEO,gDAAkB;AA1DxB,+DAA+D;AACxD,+BAAY,GAAwB,CAAC;IAC1C,2CAA2C,EAAE;QAC3C,IAAI,EAAE;YACJ,OAAO,EAAE,eAAe;YACxB,aAAa,EAAE;gBACb,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,CAAC;gBAC/C,QAAQ,EAAE,CAAC,SAAS,CAAC;aACtB;YACD,UAAU,EAAE,IAAI;SACjB;KACF;CACF,CAAC,CAAC"}
package/lib/compare.js CHANGED
@@ -1,12 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
3
  import {getImagesMatches, getImagesSimilarity, getImageOccurrence} from '@appium/opencv';
4
-
5
- const MATCH_FEATURES_MODE = 'matchFeatures';
6
- const GET_SIMILARITY_MODE = 'getSimilarity';
7
- const MATCH_TEMPLATE_MODE = 'matchTemplate';
8
-
9
- const DEFAULT_MATCH_THRESHOLD = 0.4;
4
+ import {MATCH_FEATURES_MODE, GET_SIMILARITY_MODE, MATCH_TEMPLATE_MODE} from './constants';
10
5
 
11
6
  /**
12
7
  * Performs images comparison using OpenCV framework features.
@@ -15,9 +10,9 @@ const DEFAULT_MATCH_THRESHOLD = 0.4;
15
10
  *
16
11
  * @param {string} mode - One of possible comparison modes:
17
12
  * matchFeatures, getSimilarity, matchTemplate
18
- * @param {string} firstImage - Base64-encoded image file.
13
+ * @param {string|Buffer} firstImage - Base64-encoded image file.
19
14
  * All image formats, that OpenCV library itself accepts, are supported.
20
- * @param {string} secondImage - Base64-encoded image file.
15
+ * @param {string|Buffer} secondImage - Base64-encoded image file.
21
16
  * All image formats, that OpenCV library itself accepts, are supported.
22
17
  * @param {object} [options] - The content of this dictionary depends
23
18
  * on the actual `mode` value. See the documentation on `@appium/support`
@@ -34,8 +29,8 @@ const DEFAULT_MATCH_THRESHOLD = 0.4;
34
29
  * @type {import('@appium/types').PluginCommand<[string, string, string, object|undefined], Promise<OccurrenceResult>>}
35
30
  */
36
31
  async function compareImages(mode, firstImage, secondImage, options = {}) {
37
- const img1 = Buffer.from(firstImage, 'base64');
38
- const img2 = Buffer.from(secondImage, 'base64');
32
+ const img1 = Buffer.isBuffer(firstImage) ? firstImage : Buffer.from(firstImage, 'base64');
33
+ const img2 = Buffer.isBuffer(secondImage) ? secondImage : Buffer.from(secondImage, 'base64');
39
34
  let result = null;
40
35
  switch (_.toLower(mode)) {
41
36
  case MATCH_FEATURES_MODE.toLowerCase():
@@ -84,13 +79,7 @@ function convertVisualizationToBase64(element) {
84
79
  return element;
85
80
  }
86
81
 
87
- export {
88
- compareImages,
89
- DEFAULT_MATCH_THRESHOLD,
90
- MATCH_TEMPLATE_MODE,
91
- MATCH_FEATURES_MODE,
92
- GET_SIMILARITY_MODE,
93
- };
82
+ export {compareImages};
94
83
 
95
84
  /**
96
85
  * @typedef {import('@appium/opencv').OccurrenceResult} OccurrenceResult
@@ -0,0 +1,70 @@
1
+ import {node} from 'appium/support';
2
+
3
+ export const IMAGE_STRATEGY = '-image';
4
+
5
+ export const IMAGE_ELEMENT_PREFIX = 'appium-image-element-';
6
+ export const IMAGE_EL_TAP_STRATEGY_W3C = 'w3cActions';
7
+ export const IMAGE_EL_TAP_STRATEGY_MJSONWP = 'touchActions';
8
+ export const IMAGE_TAP_STRATEGIES = [IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C];
9
+ export const DEFAULT_TEMPLATE_IMAGE_SCALE = 1.0;
10
+
11
+ export const MATCH_FEATURES_MODE = 'matchFeatures';
12
+ export const GET_SIMILARITY_MODE = 'getSimilarity';
13
+ export const MATCH_TEMPLATE_MODE = 'matchTemplate';
14
+
15
+ export const DEFAULT_MATCH_THRESHOLD = 0.4;
16
+
17
+ export const DEFAULT_FIX_IMAGE_TEMPLATE_SCALE = 1;
18
+
19
+ export const DEFAULT_SETTINGS = node.deepFreeze({
20
+ // value between 0 and 1 representing match strength, below which an image
21
+ // element will not be found
22
+ imageMatchThreshold: DEFAULT_MATCH_THRESHOLD,
23
+
24
+ // One of possible image matching methods.
25
+ // Read https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html
26
+ // for more details.
27
+ // TM_CCOEFF_NORMED by default
28
+ imageMatchMethod: '',
29
+
30
+ // if the image returned by getScreenshot differs in size or aspect ratio
31
+ // from the screen, attempt to fix it automatically
32
+ fixImageFindScreenshotDims: true,
33
+
34
+ // whether Appium should ensure that an image template sent in during image
35
+ // element find should have its size adjusted so the match algorithm will not
36
+ // complain
37
+ fixImageTemplateSize: false,
38
+
39
+ // whether Appium should ensure that an image template sent in during image
40
+ // element find should have its scale adjusted to display size so the match
41
+ // algorithm will not complain.
42
+ // e.g. iOS has `width=375, height=667` window rect, but its screenshot is
43
+ // `width=750 × height=1334` pixels. This setting help to adjust the scale
44
+ // if a user use `width=750 × height=1334` pixels's base template image.
45
+ fixImageTemplateScale: false,
46
+
47
+ // Users might have scaled template image to reduce their storage size.
48
+ // This setting allows users to scale a template image they send to Appium server
49
+ // so that the Appium server compares the actual scale users originally had.
50
+ // e.g. If a user has an image of 270 x 32 pixels which was originally 1080 x 126 pixels,
51
+ // the user can set {defaultImageTemplateScale: 4.0} to scale the small image
52
+ // to the original one so that Appium can compare it as the original one.
53
+ defaultImageTemplateScale: DEFAULT_TEMPLATE_IMAGE_SCALE,
54
+
55
+ // whether Appium should re-check that an image element can be matched
56
+ // against the current screenshot before clicking it
57
+ checkForImageElementStaleness: true,
58
+
59
+ // whether before clicking on an image element Appium should re-determine the
60
+ // position of the element on screen
61
+ autoUpdateImageElementPosition: false,
62
+
63
+ // which method to use for tapping by coordinate for image elements. the
64
+ // options are 'w3c' or 'mjsonwp'
65
+ imageElementTapStrategy: IMAGE_EL_TAP_STRATEGY_W3C,
66
+
67
+ // which method to use to save the matched image area in ImageElement class.
68
+ // It is used for debugging purpose.
69
+ getMatchedImageResult: false,
70
+ });