@appium/images-plugin 1.3.7 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/build/lib/compare.js +77 -59
- package/build/lib/compare.js.map +1 -1
- package/build/lib/finder.d.ts.map +1 -1
- package/build/lib/finder.js +378 -322
- package/build/lib/finder.js.map +1 -1
- package/build/lib/image-element.js +215 -192
- package/build/lib/image-element.js.map +1 -1
- package/build/lib/logger.js +5 -15
- package/build/lib/logger.js.map +1 -1
- package/build/lib/plugin.d.ts +7 -7
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +67 -88
- package/build/lib/plugin.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/finder.js +5 -2
- package/lib/plugin.js +2 -2
- package/package.json +5 -10
package/README.md
CHANGED
|
@@ -8,9 +8,6 @@ This is an official Appium plugin designed to facilitate image comparison, visua
|
|
|
8
8
|
2. **Finding Elements by Image** ([docs](./docs/find-by-image.md)) - Using a template image, find a matching screen region of an app and interact with it via standard Appium element semantics.
|
|
9
9
|
|
|
10
10
|
## Prerequisites
|
|
11
|
-
|
|
12
|
-
* [OpenCV](https://opencv.org) 3.x native libraries
|
|
13
|
-
* [opencv4nodejs](https://github.com/justadudewhohacks/opencv4nodejs) NPM module: install with `npm i -g opencv4nodejs`. By default the preinstall script of this module also downloads and makes all the required OpenCV libs from source, but this requires developer tools to be available on the host system.
|
|
14
11
|
* Appium Server 2.0+
|
|
15
12
|
|
|
16
13
|
## Installation - Server
|
package/build/lib/compare.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
require("
|
|
10
|
-
|
|
11
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
|
-
|
|
13
|
-
var _driver = require("appium/driver");
|
|
14
|
-
|
|
15
|
-
var _opencv = require("@appium/opencv");
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GET_SIMILARITY_MODE = exports.MATCH_FEATURES_MODE = exports.MATCH_TEMPLATE_MODE = exports.DEFAULT_MATCH_THRESHOLD = exports.compareImages = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const driver_1 = require("appium/driver");
|
|
9
|
+
const opencv_1 = require("@appium/opencv");
|
|
19
10
|
const MATCH_FEATURES_MODE = 'matchFeatures';
|
|
20
11
|
exports.MATCH_FEATURES_MODE = MATCH_FEATURES_MODE;
|
|
21
12
|
const GET_SIMILARITY_MODE = 'getSimilarity';
|
|
@@ -24,49 +15,76 @@ const MATCH_TEMPLATE_MODE = 'matchTemplate';
|
|
|
24
15
|
exports.MATCH_TEMPLATE_MODE = MATCH_TEMPLATE_MODE;
|
|
25
16
|
const DEFAULT_MATCH_THRESHOLD = 0.4;
|
|
26
17
|
exports.DEFAULT_MATCH_THRESHOLD = DEFAULT_MATCH_THRESHOLD;
|
|
27
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Performs images comparison using OpenCV framework features.
|
|
20
|
+
* It is expected that both OpenCV framework and opencv4nodejs
|
|
21
|
+
* module are installed on the machine where Appium server is running.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} mode - One of possible comparison modes:
|
|
24
|
+
* matchFeatures, getSimilarity, matchTemplate
|
|
25
|
+
* @param {string} firstImage - Base64-encoded image file.
|
|
26
|
+
* All image formats, that OpenCV library itself accepts, are supported.
|
|
27
|
+
* @param {string} secondImage - Base64-encoded image file.
|
|
28
|
+
* All image formats, that OpenCV library itself accepts, are supported.
|
|
29
|
+
* @param {object} [options] - The content of this dictionary depends
|
|
30
|
+
* on the actual `mode` value. See the documentation on `@appium/support`
|
|
31
|
+
* module for more details.
|
|
32
|
+
* @returns {Promise<object|object[]>} The content of the resulting dictionary depends
|
|
33
|
+
* on the actual `mode` and `options` values. See the documentation on
|
|
34
|
+
* `@appium/support` module for more details.
|
|
35
|
+
* @throws {Error} If required OpenCV modules are not installed or
|
|
36
|
+
* if `mode` value is incorrect or if there was an unexpected issue while
|
|
37
|
+
* matching the images.
|
|
38
|
+
*/
|
|
28
39
|
async function compareImages(mode, firstImage, secondImage, options = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return convertVisualizationToBase64(result);
|
|
40
|
+
const img1 = Buffer.from(firstImage, 'base64');
|
|
41
|
+
const img2 = Buffer.from(secondImage, 'base64');
|
|
42
|
+
let result = null;
|
|
43
|
+
switch (lodash_1.default.toLower(mode)) {
|
|
44
|
+
case MATCH_FEATURES_MODE.toLowerCase():
|
|
45
|
+
try {
|
|
46
|
+
result = await (0, opencv_1.getImagesMatches)(img1, img2, options);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
// might throw if no matches
|
|
50
|
+
result = { count: 0 };
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case GET_SIMILARITY_MODE.toLowerCase():
|
|
54
|
+
result = await (0, opencv_1.getImagesSimilarity)(img1, img2, options);
|
|
55
|
+
break;
|
|
56
|
+
case MATCH_TEMPLATE_MODE.toLowerCase():
|
|
57
|
+
// firstImage/img1 is the full image and secondImage/img2 is the partial one
|
|
58
|
+
result = await (0, opencv_1.getImageOccurrence)(img1, img2, options);
|
|
59
|
+
if (options.multiple) {
|
|
60
|
+
return result.multiple.map(convertVisualizationToBase64);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
throw new driver_1.errors.InvalidArgumentError(`'${mode}' images comparison mode is unknown. ` +
|
|
65
|
+
`Only ${JSON.stringify([
|
|
66
|
+
MATCH_FEATURES_MODE,
|
|
67
|
+
GET_SIMILARITY_MODE,
|
|
68
|
+
MATCH_TEMPLATE_MODE,
|
|
69
|
+
])} modes are supported.`);
|
|
70
|
+
}
|
|
71
|
+
return convertVisualizationToBase64(result);
|
|
63
72
|
}
|
|
64
|
-
|
|
73
|
+
exports.compareImages = compareImages;
|
|
74
|
+
/**
|
|
75
|
+
* base64 encodes the visualization part of the result
|
|
76
|
+
* (if necessary)
|
|
77
|
+
*
|
|
78
|
+
* @param {OccurrenceResult} element - occurrence result
|
|
79
|
+
*
|
|
80
|
+
**/
|
|
65
81
|
function convertVisualizationToBase64(element) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return element;
|
|
82
|
+
if (!lodash_1.default.isEmpty(element.visualization)) {
|
|
83
|
+
element.visualization = element.visualization.toString('base64');
|
|
84
|
+
}
|
|
85
|
+
return element;
|
|
71
86
|
}
|
|
72
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {import('@appium/opencv').OccurrenceResult} OccurrenceResult
|
|
89
|
+
*/
|
|
90
|
+
//# sourceMappingURL=compare.js.map
|
package/build/lib/compare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","
|
|
1
|
+
{"version":3,"file":"compare.js","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,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;aAC1D;YACD,MAAM;QACR;YACE,MAAM,IAAI,eAAM,CAAC,oBAAoB,CACnC,IAAI,IAAI,uCAAuC;gBAC7C,QAAQ,IAAI,CAAC,SAAS,CAAC;oBACrB,mBAAmB;oBACnB,mBAAmB;oBACnB,mBAAmB;iBACpB,CAAC,uBAAuB,CAC5B,CAAC;KACL;IACD,OAAO,4BAA4B,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAkBC,sCAAa;AAhBf;;;;;;IAMI;AACJ,SAAS,4BAA4B,CAAC,OAAO;IAC3C,IAAI,CAAC,gBAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACrC,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAClE;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAUD;;GAEG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../../lib/finder.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../../lib/finder.js"],"names":[],"mappings":"AA6EA;IAOE;;;;OAIG;IACH,oBAHW,cAAc,gCAUxB;IAlBD,6BAA6B;IAC7B,QADW,cAAc,CAClB;IAEP,uCAAuC;IACvC,YADW,IAAI,MAAM,EAAC,YAAY,CAAC,CACxB;IAgBX,6BAEC;IAED;;;OAGG;IACH,4BAHW,YAAY,GACV,OAAO,CAMnB;IAED;;;;;;;;;OASG;IAEH;;;;;;;;;OASG;IACH,yBANW,MAAM;;;;;;;;;;;;;;;;;QAIJ,QAAQ,OAAO,GAAC,OAAO,EAAE,GAAC,YAAY,CAAC,CAuHnD;IAED;;;;;;;;OAQG;IACH,gCANW,MAAM,eACN,MAAM,gBACN,MAAM,GAEJ,QAAQ,MAAM,CAAC,CAqB3B;IAED;;;;;;;;OAQG;IACH,uCALW,MAAM,gBACN,MAAM;;OAuHhB;IAED;;;;;;;;;;OAUG;IACH;;;;;;;;;;OAUG;IACH,mCANW,MAAM;;;;+BAdH,OAAO;;;;mCACP,MAAM;;;;;;yCACN,OAAO;;;;gBAGP,MAAM;;;;gBACN,MAAM;QAYP,QAAQ,MAAM,CAAC,CA+D3B;CACF;6BAKY,OAAO,eAAe,EAAE,cAAc;sBACtC,OAAO,eAAe,EAAE,OAAO;;;;;mBAK9B,MAAM;;;;;;YAKN,MAAM;;;;YACN,MAAM;;;;AAhfpB,oEAAwD;AADxD,4CAAsC;;;;;;;;;;;;;AAEtC,iDAA2C"}
|