@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.
- package/README.md +2 -2
- package/build/lib/compare.d.ts +2 -2
- package/build/lib/compare.d.ts.map +1 -1
- package/build/lib/compare.js +13 -20
- package/build/lib/compare.js.map +1 -1
- package/build/lib/constants.d.ts +1 -1
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +16 -22
- package/build/lib/constants.js.map +1 -1
- package/build/lib/finder.d.ts +3 -3
- package/build/lib/finder.d.ts.map +1 -1
- package/build/lib/finder.js +38 -47
- package/build/lib/finder.js.map +1 -1
- package/build/lib/image-element.d.ts +4 -5
- package/build/lib/image-element.d.ts.map +1 -1
- package/build/lib/image-element.js +26 -31
- package/build/lib/image-element.js.map +1 -1
- package/build/lib/index.d.ts +7 -7
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +6 -29
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.js +2 -5
- package/build/lib/logger.js.map +1 -1
- package/build/lib/plugin.d.ts +4 -4
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +23 -27
- package/build/lib/plugin.js.map +1 -1
- package/build/lib/types.d.ts +3 -3
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/types.js +1 -2
- package/lib/compare.ts +10 -13
- package/lib/constants.ts +4 -6
- package/lib/finder.ts +19 -33
- package/lib/image-element.ts +14 -32
- package/lib/index.ts +7 -7
- package/lib/logger.ts +1 -1
- package/lib/plugin.ts +16 -27
- package/lib/types.ts +4 -3
- package/package.json +31 -25
- package/tsconfig.json +14 -5
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const support_1 = require("@appium/support");
|
|
6
|
-
const logger_1 = require("./logger");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { util } from '@appium/support';
|
|
2
|
+
import { errors } from 'appium/driver.js';
|
|
3
|
+
import { DEFAULT_SETTINGS, IMAGE_EL_TAP_STRATEGY_W3C, IMAGE_ELEMENT_PREFIX, IMAGE_STRATEGY, IMAGE_TAP_STRATEGIES, } from './constants.js';
|
|
4
|
+
import { log } from './logger.js';
|
|
8
5
|
const TAP_DURATION_MS = 125;
|
|
9
6
|
/**
|
|
10
7
|
* Representation of an "image element", which is simply a set of coordinates
|
|
11
8
|
* and methods that can be used on that set of coordinates via the driver
|
|
12
9
|
*/
|
|
13
|
-
class ImageElement {
|
|
10
|
+
export class ImageElement {
|
|
14
11
|
template;
|
|
15
12
|
rect;
|
|
16
13
|
id;
|
|
@@ -18,10 +15,10 @@ class ImageElement {
|
|
|
18
15
|
score;
|
|
19
16
|
finder;
|
|
20
17
|
containerRect;
|
|
21
|
-
constructor({ template, rect, score, match = null, finder = null, containerRect = null
|
|
18
|
+
constructor({ template, rect, score, match = null, finder = null, containerRect = null }) {
|
|
22
19
|
this.template = template;
|
|
23
20
|
this.rect = rect;
|
|
24
|
-
this.id = `${
|
|
21
|
+
this.id = `${IMAGE_ELEMENT_PREFIX}${util.uuidV4()}`;
|
|
25
22
|
this.match = match;
|
|
26
23
|
this.score = score;
|
|
27
24
|
this.finder = finder;
|
|
@@ -99,18 +96,17 @@ class ImageElement {
|
|
|
99
96
|
case 'score':
|
|
100
97
|
return imgEl.score;
|
|
101
98
|
default:
|
|
102
|
-
throw new
|
|
99
|
+
throw new errors.NotYetImplementedError();
|
|
103
100
|
}
|
|
104
101
|
default:
|
|
105
|
-
throw new
|
|
102
|
+
throw new errors.NotYetImplementedError();
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
/**
|
|
109
|
-
*
|
|
110
106
|
* @returns this image element as a WebElement
|
|
111
107
|
*/
|
|
112
108
|
asElement() {
|
|
113
|
-
return
|
|
109
|
+
return util.wrapElement(this.id);
|
|
114
110
|
}
|
|
115
111
|
/**
|
|
116
112
|
* @param other - an ImageElement to compare with this one
|
|
@@ -132,20 +128,20 @@ class ImageElement {
|
|
|
132
128
|
async click(driver) {
|
|
133
129
|
// before we click we need to make sure the element is actually still there
|
|
134
130
|
// where we expect it to be
|
|
135
|
-
const settings = { ...
|
|
131
|
+
const settings = { ...DEFAULT_SETTINGS, ...driver.settings.getSettings() };
|
|
136
132
|
const { autoUpdateImageElementPosition: updatePos, checkForImageElementStaleness, imageElementTapStrategy, } = settings;
|
|
137
133
|
// validate tap strategy
|
|
138
|
-
if (!
|
|
134
|
+
if (!IMAGE_TAP_STRATEGIES.includes(imageElementTapStrategy)) {
|
|
139
135
|
throw new Error(`Incorrect imageElementTapStrategy setting ` +
|
|
140
136
|
`'${imageElementTapStrategy}'. Must be one of ` +
|
|
141
|
-
JSON.stringify(
|
|
137
|
+
JSON.stringify(IMAGE_TAP_STRATEGIES));
|
|
142
138
|
}
|
|
143
139
|
let newImgEl;
|
|
144
140
|
if (checkForImageElementStaleness || updatePos) {
|
|
145
|
-
|
|
141
|
+
log.info('Checking image element for staleness before clicking');
|
|
146
142
|
try {
|
|
147
143
|
if (!this.finder) {
|
|
148
|
-
throw new
|
|
144
|
+
throw new errors.StaleElementReferenceError();
|
|
149
145
|
}
|
|
150
146
|
newImgEl = (await this.finder.findByImage(this.template, driver, {
|
|
151
147
|
shouldCheckStaleness: true,
|
|
@@ -156,19 +152,19 @@ class ImageElement {
|
|
|
156
152
|
}));
|
|
157
153
|
}
|
|
158
154
|
catch {
|
|
159
|
-
throw new
|
|
155
|
+
throw new errors.StaleElementReferenceError();
|
|
160
156
|
}
|
|
161
157
|
if (!this.equals(newImgEl)) {
|
|
162
|
-
|
|
158
|
+
log.warn(`When trying to click on an image element, the image changed ` +
|
|
163
159
|
`position from where it was originally found. It is now at ` +
|
|
164
160
|
`${JSON.stringify(newImgEl.rect)} and was originally at ` +
|
|
165
161
|
`${JSON.stringify(this.rect)}.`);
|
|
166
162
|
if (updatePos) {
|
|
167
|
-
|
|
163
|
+
log.warn('Click will proceed at new coordinates');
|
|
168
164
|
this.rect = { ...newImgEl.rect };
|
|
169
165
|
}
|
|
170
166
|
else {
|
|
171
|
-
|
|
167
|
+
log.warn('Click will take place at original coordinates. If you ' +
|
|
172
168
|
'would like Appium to automatically click the new ' +
|
|
173
169
|
"coordinates, set the 'autoUpdateImageElementPosition' " +
|
|
174
170
|
'setting to true');
|
|
@@ -176,10 +172,10 @@ class ImageElement {
|
|
|
176
172
|
}
|
|
177
173
|
}
|
|
178
174
|
const { x, y } = this.center;
|
|
179
|
-
|
|
180
|
-
if (imageElementTapStrategy ===
|
|
175
|
+
log.info(`Will tap on image element at coordinate [${x}, ${y}]`);
|
|
176
|
+
if (imageElementTapStrategy === IMAGE_EL_TAP_STRATEGY_W3C) {
|
|
181
177
|
// set up a W3C action to click on the image by position
|
|
182
|
-
|
|
178
|
+
log.info('Will tap using W3C actions');
|
|
183
179
|
const action = {
|
|
184
180
|
type: 'pointer',
|
|
185
181
|
id: 'mouse',
|
|
@@ -196,11 +192,11 @@ class ImageElement {
|
|
|
196
192
|
return await driver.performActions([action]);
|
|
197
193
|
}
|
|
198
194
|
// if not, warn and fall back to the other method
|
|
199
|
-
|
|
195
|
+
log.warn('Driver does not seem to implement W3C actions, falling back ' + 'to TouchActions');
|
|
200
196
|
}
|
|
201
197
|
// if the w3c strategy was not requested, do the only other option (mjsonwp
|
|
202
198
|
// touch actions)
|
|
203
|
-
|
|
199
|
+
log.info('Will tap using MJSONWP TouchActions');
|
|
204
200
|
const action = {
|
|
205
201
|
action: 'tap',
|
|
206
202
|
options: { x, y },
|
|
@@ -222,8 +218,8 @@ class ImageElement {
|
|
|
222
218
|
*/
|
|
223
219
|
async find(multiple, driver, ...args) {
|
|
224
220
|
const [strategy, selector] = args;
|
|
225
|
-
if (strategy !==
|
|
226
|
-
throw new
|
|
221
|
+
if (strategy !== IMAGE_STRATEGY) {
|
|
222
|
+
throw new errors.InvalidSelectorError(`Lookup strategies other than '${IMAGE_STRATEGY}' are not supported`);
|
|
227
223
|
}
|
|
228
224
|
if (!this.finder) {
|
|
229
225
|
throw new Error('Finder is not available');
|
|
@@ -234,5 +230,4 @@ class ImageElement {
|
|
|
234
230
|
});
|
|
235
231
|
}
|
|
236
232
|
}
|
|
237
|
-
exports.ImageElement = ImageElement;
|
|
238
233
|
//# sourceMappingURL=image-element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-element.js","sourceRoot":"","sources":["../../lib/image-element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-element.js","sourceRoot":"","sources":["../../lib/image-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAGhC,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;GAGG;AACH,MAAM,OAAO,YAAY;IACd,QAAQ,CAAS;IAC1B,IAAI,CAAO;IACF,EAAE,CAAS;IACX,KAAK,CAAgB;IACrB,KAAK,CAAS;IACd,MAAM,CAA4B;IAClC,aAAa,CAAc;IAEpC,YAAY,EAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,aAAa,GAAG,IAAI,EAAmB;QACtG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,GAAG,oBAAoB,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,I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E,IAAI,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { IMAGE_STRATEGY } from './constants';
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
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';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/build/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACjE,mBAAmB,YAAY,CAAC"}
|
package/build/lib/index.js
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.compareImages = exports.ImageElement = exports.ImageElementFinder = exports.IMAGE_STRATEGY = exports.getImgElFromArgs = exports.ImageElementPlugin = void 0;
|
|
18
|
-
var plugin_1 = require("./plugin");
|
|
19
|
-
Object.defineProperty(exports, "ImageElementPlugin", { enumerable: true, get: function () { return plugin_1.ImageElementPlugin; } });
|
|
20
|
-
Object.defineProperty(exports, "getImgElFromArgs", { enumerable: true, get: function () { return plugin_1.getImgElFromArgs; } });
|
|
21
|
-
var constants_1 = require("./constants");
|
|
22
|
-
Object.defineProperty(exports, "IMAGE_STRATEGY", { enumerable: true, get: function () { return constants_1.IMAGE_STRATEGY; } });
|
|
23
|
-
var finder_1 = require("./finder");
|
|
24
|
-
Object.defineProperty(exports, "ImageElementFinder", { enumerable: true, get: function () { return finder_1.ImageElementFinder; } });
|
|
25
|
-
var image_element_1 = require("./image-element");
|
|
26
|
-
Object.defineProperty(exports, "ImageElement", { enumerable: true, get: function () { return image_element_1.ImageElement; } });
|
|
27
|
-
__exportStar(require("./constants"), exports);
|
|
28
|
-
var compare_1 = require("./compare");
|
|
29
|
-
Object.defineProperty(exports, "compareImages", { enumerable: true, get: function () { return compare_1.compareImages; } });
|
|
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';
|
|
30
7
|
//# sourceMappingURL=index.js.map
|
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC"}
|
package/build/lib/logger.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.log = void 0;
|
|
4
|
-
const support_1 = require("appium/support");
|
|
5
|
-
exports.log = support_1.logger.getLogger('ImageElementPlugin');
|
|
1
|
+
import { logger } from 'appium/support.js';
|
|
2
|
+
export const log = logger.getLogger('ImageElementPlugin');
|
|
6
3
|
//# sourceMappingURL=logger.js.map
|
package/build/lib/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAEzC,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC"}
|
package/build/lib/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import type { MatchingOptions, OccurrenceOptions, SimilarityOptions } from '@appium/opencv';
|
|
2
|
+
import type { ActionSequence, ExternalDriver, MethodMap } from '@appium/types';
|
|
3
|
+
import { BasePlugin } from 'appium/plugin.js';
|
|
4
|
+
import { ImageElementFinder } from './finder.js';
|
|
5
5
|
export declare class ImageElementPlugin extends BasePlugin {
|
|
6
6
|
static newMethodMap: MethodMap<ImageElementPlugin>;
|
|
7
7
|
readonly finder: ImageElementFinder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAE1F,OAAO,KAAK,EAAC,cAAc,EAAW,cAAc,EAAE,SAAS,EAAC,MAAM,eAAe,CAAC;AAEtF,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAI5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAG/C,qBAAa,kBAAmB,SAAQ,UAAU;IAEhD,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAWvC;IACX,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;gBAExB,UAAU,EAAE,MAAM;IAKxB,aAAa,CACjB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACxB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,CAAC,EAAE,eAAe,GAAG,iBAAiB,GAAG,iBAAiB,GAChE,OAAO,CAAC,GAAG,CAAC;IAIT,WAAW,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAI3F,YAAY,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAI5F,MAAM,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAoBvG,cAAc,CAClB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACxB,MAAM,EAAE,cAAc,EACtB,eAAe,EAAE,cAAc,EAAE,GAChC,OAAO,CAAC,GAAG,CAAC;YAiCD,KAAK;CAepB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,GAAG,SAAS,CAEhE"}
|
package/build/lib/plugin.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const finder_1 = require("./finder");
|
|
10
|
-
const image_element_1 = require("./image-element");
|
|
11
|
-
const constants_1 = require("./constants");
|
|
12
|
-
class ImageElementPlugin extends plugin_1.BasePlugin {
|
|
1
|
+
import { util } from '@appium/support';
|
|
2
|
+
import { errors } from 'appium/driver.js';
|
|
3
|
+
import { BasePlugin } from 'appium/plugin.js';
|
|
4
|
+
import { compareImages } from './compare.js';
|
|
5
|
+
import { IMAGE_ELEMENT_PREFIX, IMAGE_STRATEGY } from './constants.js';
|
|
6
|
+
import { ImageElementFinder } from './finder.js';
|
|
7
|
+
import { ImageElement } from './image-element.js';
|
|
8
|
+
export class ImageElementPlugin extends BasePlugin {
|
|
13
9
|
// this plugin supports a non-standard 'compare images' command
|
|
14
10
|
static newMethodMap = {
|
|
15
11
|
'/session/:sessionId/appium/compare_images': {
|
|
@@ -26,10 +22,10 @@ class ImageElementPlugin extends plugin_1.BasePlugin {
|
|
|
26
22
|
finder;
|
|
27
23
|
constructor(pluginName) {
|
|
28
24
|
super(pluginName);
|
|
29
|
-
this.finder = new
|
|
25
|
+
this.finder = new ImageElementFinder();
|
|
30
26
|
}
|
|
31
27
|
async compareImages(next, driver, mode, firstImage, secondImage, options) {
|
|
32
|
-
return await
|
|
28
|
+
return await compareImages(mode, firstImage, secondImage, options);
|
|
33
29
|
}
|
|
34
30
|
async findElement(next, driver, ...args) {
|
|
35
31
|
return await this._find(false, next, driver, ...args);
|
|
@@ -44,9 +40,9 @@ class ImageElementPlugin extends plugin_1.BasePlugin {
|
|
|
44
40
|
if (imgElId) {
|
|
45
41
|
const imgEl = this.finder.getImageElement(imgElId);
|
|
46
42
|
if (!imgEl) {
|
|
47
|
-
throw new
|
|
43
|
+
throw new errors.NoSuchElementError();
|
|
48
44
|
}
|
|
49
|
-
return await
|
|
45
|
+
return await ImageElement.execute(driver, imgEl, cmdName, ...args);
|
|
50
46
|
}
|
|
51
47
|
if (cmdName === 'deleteSession') {
|
|
52
48
|
this.finder.clearImageElements();
|
|
@@ -59,21 +55,22 @@ class ImageElementPlugin extends plugin_1.BasePlugin {
|
|
|
59
55
|
for (const actionSequence of actionSequences) {
|
|
60
56
|
for (const action of actionSequence.actions) {
|
|
61
57
|
// The actions that can have an Element as the origin are "pointerMove" and "scroll".
|
|
62
|
-
if (!
|
|
58
|
+
if (!util.isPlainObject(action.origin)) {
|
|
63
59
|
continue;
|
|
64
60
|
}
|
|
65
61
|
const actionWithEl = action;
|
|
66
|
-
const elId =
|
|
67
|
-
if (!elId?.startsWith(
|
|
62
|
+
const elId = util.unwrapElement(actionWithEl.origin);
|
|
63
|
+
if (!elId?.startsWith(IMAGE_ELEMENT_PREFIX)) {
|
|
68
64
|
continue;
|
|
69
65
|
}
|
|
70
66
|
const imgEl = this.finder.getImageElement(elId);
|
|
71
67
|
if (!imgEl) {
|
|
72
|
-
throw new
|
|
68
|
+
throw new errors.NoSuchElementError();
|
|
73
69
|
}
|
|
74
|
-
// Add the element's center
|
|
75
|
-
|
|
76
|
-
actionWithEl.
|
|
70
|
+
// Add the element's center to the offset. An unset offset must count as
|
|
71
|
+
// zero, otherwise the resulting coordinate is NaN.
|
|
72
|
+
actionWithEl.x = (actionWithEl.x ?? 0) + imgEl.center.x;
|
|
73
|
+
actionWithEl.y = (actionWithEl.y ?? 0) + imgEl.center.y;
|
|
77
74
|
// Set the origin to the viewport so that the external driver can process it using coordinates.
|
|
78
75
|
delete actionWithEl.origin;
|
|
79
76
|
}
|
|
@@ -83,18 +80,17 @@ class ImageElementPlugin extends plugin_1.BasePlugin {
|
|
|
83
80
|
async _find(multiple, next, driver, ...args) {
|
|
84
81
|
const [strategy, selector] = args;
|
|
85
82
|
// if we're not actually finding by image, just do the normal thing
|
|
86
|
-
if (strategy !==
|
|
83
|
+
if (strategy !== IMAGE_STRATEGY) {
|
|
87
84
|
return await next();
|
|
88
85
|
}
|
|
89
86
|
return await this.finder.findByImage(Buffer.from(selector, 'base64'), driver, { multiple });
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
exports.ImageElementPlugin = ImageElementPlugin;
|
|
93
89
|
/**
|
|
94
90
|
* Returns the first image-element id found in command args.
|
|
95
91
|
* @param args Command arguments.
|
|
96
92
|
*/
|
|
97
|
-
function getImgElFromArgs(args) {
|
|
98
|
-
return args.find((arg) => typeof arg === 'string' && arg.startsWith(
|
|
93
|
+
export function getImgElFromArgs(args) {
|
|
94
|
+
return args.find((arg) => typeof arg === 'string' && arg.startsWith(IMAGE_ELEMENT_PREFIX));
|
|
99
95
|
}
|
|
100
96
|
//# sourceMappingURL=plugin.js.map
|
package/build/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAE,cAAc,EAAC,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAChD,+DAA+D;IAC/D,MAAM,CAAC,YAAY,GAAkC;QACnD,2CAA2C,EAAE;YAC3C,IAAI,EAAE;gBACJ,OAAO,EAAE,eAAe;gBACxB,aAAa,EAAE;oBACb,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,CAAC;oBAC/C,QAAQ,EAAE,CAAC,SAAS,CAAC;iBACtB;gBACD,UAAU,EAAE,IAAI;aACjB;SACF;KACO,CAAC;IACF,MAAM,CAAqB;IAEpC,YAAY,UAAkB;QAC5B,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,IAAwB,EACxB,MAAsB,EACtB,IAAY,EACZ,UAA2B,EAC3B,WAA4B,EAC5B,OAAiE;QAEjE,OAAO,MAAM,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAA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AC,QAAQ,EAAC,CAAC,CAAC;IAC5F,CAAC;;AAGH;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAW;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAC7F,CAAC"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
2
|
+
import type { Rect } from '@appium/types';
|
|
3
|
+
import type { IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C } from './constants.js';
|
|
4
|
+
import type { ImageElementFinder } from './finder.js';
|
|
5
5
|
/**
|
|
6
6
|
* Image settings interface for device settings
|
|
7
7
|
*/
|
package/build/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AACvF,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAC,6BAA6B,EAAE,yBAAyB,EAAC,MAAM,gBAAgB,CAAC;AAC7F,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,aAAa;IAG5B,mBAAmB,EAAE,MAAM,CAAC;IAM5B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C;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,+CAA+C;IAC/C,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mDAAmD;IACnD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;2EAEuE;IACvE,+BAA+B,CAAC,EAAE,OAAO,CAAC;IAC1C,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,cAAc,GAAG,UAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,wBAAwB,GACxB,0BAA0B,GAC1B,0BAA0B,GAC1B,0BAA0B,EAAE,CAAC"}
|
package/build/lib/types.js
CHANGED
package/lib/compare.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {errors} from 'appium/driver';
|
|
2
1
|
import {
|
|
2
|
+
getImageOccurrence,
|
|
3
3
|
getImagesMatches,
|
|
4
4
|
getImagesSimilarity,
|
|
5
|
-
|
|
5
|
+
type MatchingOptions,
|
|
6
6
|
type MatchingResult,
|
|
7
|
+
type OccurrenceOptions,
|
|
7
8
|
type OccurrenceResult,
|
|
8
|
-
type SimilarityResult,
|
|
9
|
-
type MatchingOptions,
|
|
10
9
|
type SimilarityOptions,
|
|
11
|
-
type
|
|
10
|
+
type SimilarityResult,
|
|
12
11
|
} from '@appium/opencv';
|
|
13
|
-
import {
|
|
14
|
-
|
|
12
|
+
import {errors} from 'appium/driver.js';
|
|
13
|
+
|
|
14
|
+
import {GET_SIMILARITY_MODE, MATCH_FEATURES_MODE, MATCH_TEMPLATE_MODE} from './constants.js';
|
|
15
|
+
import type {ComparisonResult} from './types.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Performs images comparison using OpenCV framework features.
|
|
@@ -70,11 +71,7 @@ export async function compareImages(
|
|
|
70
71
|
default:
|
|
71
72
|
throw new errors.InvalidArgumentError(
|
|
72
73
|
`'${mode}' images comparison mode is unknown. ` +
|
|
73
|
-
`Only ${JSON.stringify([
|
|
74
|
-
MATCH_FEATURES_MODE,
|
|
75
|
-
GET_SIMILARITY_MODE,
|
|
76
|
-
MATCH_TEMPLATE_MODE,
|
|
77
|
-
])} modes are supported.`,
|
|
74
|
+
`Only ${JSON.stringify([MATCH_FEATURES_MODE, GET_SIMILARITY_MODE, MATCH_TEMPLATE_MODE])} modes are supported.`,
|
|
78
75
|
);
|
|
79
76
|
}
|
|
80
77
|
return convertVisualizationToBase64(result);
|
|
@@ -86,7 +83,7 @@ export async function compareImages(
|
|
|
86
83
|
*
|
|
87
84
|
* @param element - occurrence result
|
|
88
85
|
* @returns result with base64-encoded visualization
|
|
89
|
-
|
|
86
|
+
*/
|
|
90
87
|
function convertVisualizationToBase64(element: Partial<{visualization: Buffer | null}>): any {
|
|
91
88
|
return Buffer.isBuffer(element.visualization)
|
|
92
89
|
? {
|
package/lib/constants.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {node} from 'appium/support';
|
|
2
|
-
|
|
1
|
+
import {node} from 'appium/support.js';
|
|
2
|
+
|
|
3
|
+
import type {ImageSettings} from './types.js';
|
|
3
4
|
|
|
4
5
|
export const IMAGE_STRATEGY = '-image';
|
|
5
6
|
|
|
6
7
|
export const IMAGE_ELEMENT_PREFIX = 'appium-image-element-';
|
|
7
8
|
export const IMAGE_EL_TAP_STRATEGY_W3C = 'w3cActions';
|
|
8
9
|
export const IMAGE_EL_TAP_STRATEGY_MJSONWP = 'touchActions';
|
|
9
|
-
export const IMAGE_TAP_STRATEGIES = [
|
|
10
|
-
IMAGE_EL_TAP_STRATEGY_MJSONWP,
|
|
11
|
-
IMAGE_EL_TAP_STRATEGY_W3C,
|
|
12
|
-
] as const;
|
|
10
|
+
export const IMAGE_TAP_STRATEGIES = [IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C] as const;
|
|
13
11
|
export const DEFAULT_TEMPLATE_IMAGE_SCALE = 1.0;
|
|
14
12
|
|
|
15
13
|
export const MATCH_FEATURES_MODE = 'matchFeatures';
|
package/lib/finder.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
+
import type {Element, ExternalDriver, Rect, Size} from '@appium/types';
|
|
2
|
+
import {errors} from 'appium/driver.js';
|
|
1
3
|
import {LRUCache} from 'lru-cache';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {compareImages} from './compare';
|
|
5
|
-
import {log} from './logger';
|
|
4
|
+
import sharp from 'sharp';
|
|
5
|
+
|
|
6
|
+
import {compareImages} from './compare.js';
|
|
6
7
|
import {
|
|
8
|
+
DEFAULT_FIX_IMAGE_TEMPLATE_SCALE,
|
|
7
9
|
DEFAULT_SETTINGS,
|
|
8
|
-
MATCH_TEMPLATE_MODE,
|
|
9
10
|
DEFAULT_TEMPLATE_IMAGE_SCALE,
|
|
10
|
-
|
|
11
|
-
} from './constants';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
11
|
+
MATCH_TEMPLATE_MODE,
|
|
12
|
+
} from './constants.js';
|
|
13
|
+
import {ImageElement} from './image-element.js';
|
|
14
|
+
import {log} from './logger.js';
|
|
14
15
|
import type {
|
|
15
|
-
ImageSettings,
|
|
16
16
|
FindByImageOptions,
|
|
17
|
-
|
|
18
|
-
ScreenshotScale,
|
|
17
|
+
ImageSettings,
|
|
19
18
|
ImageTemplateSettings,
|
|
20
19
|
OccurrenceResultWithVisualization,
|
|
21
|
-
|
|
20
|
+
Screenshot,
|
|
21
|
+
ScreenshotScale,
|
|
22
|
+
} from './types.js';
|
|
22
23
|
|
|
23
24
|
// Used to compare ratio and screen width
|
|
24
25
|
// Pixel is basically under 1080 for example. 100K is probably enough fo a while.
|
|
@@ -171,12 +172,7 @@ export class ImageElementFinder {
|
|
|
171
172
|
return true;
|
|
172
173
|
};
|
|
173
174
|
|
|
174
|
-
const elOrEls = await compareImages(
|
|
175
|
-
MATCH_TEMPLATE_MODE,
|
|
176
|
-
screenshot,
|
|
177
|
-
template,
|
|
178
|
-
comparisonOpts,
|
|
179
|
-
);
|
|
175
|
+
const elOrEls = await compareImages(MATCH_TEMPLATE_MODE, screenshot, template, comparisonOpts);
|
|
180
176
|
return (Array.isArray(elOrEls) ? elOrEls : [elOrEls]).some(pushIfOk);
|
|
181
177
|
} catch (err: any) {
|
|
182
178
|
// if compareImages fails, we'll get a specific error, but we should
|
|
@@ -368,9 +364,7 @@ export class ImageElementFinder {
|
|
|
368
364
|
const xScale = (1.0 * shotWidth) / screenSize.width;
|
|
369
365
|
const yScale = (1.0 * shotHeight) / screenSize.height;
|
|
370
366
|
const scaleFactor = Math.min(xScale, yScale);
|
|
371
|
-
const [newWidth, newHeight] = [shotWidth * scaleFactor, shotHeight * scaleFactor].map(
|
|
372
|
-
Math.trunc,
|
|
373
|
-
);
|
|
367
|
+
const [newWidth, newHeight] = [shotWidth * scaleFactor, shotHeight * scaleFactor].map(Math.trunc);
|
|
374
368
|
|
|
375
369
|
log.warn(
|
|
376
370
|
`Resizing screenshot to ${newWidth}x${newHeight} to match ` +
|
|
@@ -464,14 +458,8 @@ export class ImageElementFinder {
|
|
|
464
458
|
|
|
465
459
|
// Return if the scale is default, 1, value
|
|
466
460
|
if (
|
|
467
|
-
Math.round(xScale * FLOAT_PRECISION) ===
|
|
468
|
-
|
|
469
|
-
Math.round(
|
|
470
|
-
Number(
|
|
471
|
-
yScale * FLOAT_PRECISION ===
|
|
472
|
-
Math.round(DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION),
|
|
473
|
-
),
|
|
474
|
-
)
|
|
461
|
+
Math.round(xScale * FLOAT_PRECISION) === Math.round(DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION) &&
|
|
462
|
+
Math.round(yScale * FLOAT_PRECISION) === Math.round(DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION)
|
|
475
463
|
) {
|
|
476
464
|
return template;
|
|
477
465
|
}
|
|
@@ -484,9 +472,7 @@ export class ImageElementFinder {
|
|
|
484
472
|
|
|
485
473
|
const scaledWidth = baseTempWidth * xScale;
|
|
486
474
|
const scaledHeight = baseTempHeigh * yScale;
|
|
487
|
-
log.info(
|
|
488
|
-
`Scaling template image from ${baseTempWidth}x${baseTempHeigh} to ${scaledWidth}x${scaledHeight}`,
|
|
489
|
-
);
|
|
475
|
+
log.info(`Scaling template image from ${baseTempWidth}x${baseTempHeigh} to ${scaledWidth}x${scaledHeight}`);
|
|
490
476
|
log.info(`The ratio is ${xScale} and ${yScale}`);
|
|
491
477
|
imgObj = imgObj.resize({
|
|
492
478
|
width: Math.trunc(scaledWidth),
|