@appium/images-plugin 4.0.4 → 4.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.
- package/build/lib/compare.d.ts +8 -22
- package/build/lib/compare.d.ts.map +1 -1
- package/build/lib/compare.js +17 -23
- package/build/lib/compare.js.map +1 -1
- package/build/lib/constants.d.ts +13 -12
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +0 -31
- package/build/lib/constants.js.map +1 -1
- package/build/lib/finder.d.ts +22 -121
- package/build/lib/finder.d.ts.map +1 -1
- package/build/lib/finder.js +60 -100
- package/build/lib/finder.js.map +1 -1
- package/build/lib/image-element.d.ts +36 -108
- package/build/lib/image-element.d.ts.map +1 -1
- package/build/lib/image-element.js +45 -60
- package/build/lib/image-element.js.map +1 -1
- package/build/lib/index.d.ts +8 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +30 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/logger.d.ts +1 -2
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +2 -2
- package/build/lib/logger.js.map +1 -1
- package/build/lib/plugin.d.ts +15 -34
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +12 -25
- package/build/lib/plugin.js.map +1 -1
- package/build/lib/types.d.ts +127 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/lib/compare.ts +100 -0
- package/lib/constants.ts +31 -0
- package/lib/{finder.js → finder.ts} +109 -136
- package/lib/{image-element.js → image-element.ts} +67 -85
- package/lib/index.ts +7 -0
- package/lib/logger.ts +3 -0
- package/lib/{plugin.js → plugin.ts} +42 -38
- package/lib/types.ts +187 -0
- package/package.json +14 -14
- package/tsconfig.json +3 -2
- package/index.js +0 -1
- package/lib/compare.js +0 -96
- package/lib/constants.js +0 -70
- package/lib/logger.js +0 -5
package/lib/compare.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {errors} from 'appium/driver';
|
|
3
|
-
import {getImagesMatches, getImagesSimilarity, getImageOccurrence} from '@appium/opencv';
|
|
4
|
-
import {MATCH_FEATURES_MODE, GET_SIMILARITY_MODE, MATCH_TEMPLATE_MODE} from './constants';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {{visualization: string|null|undefined}} Visualized
|
|
8
|
-
* @typedef {import('@appium/opencv').MatchingResult & Visualized} MatchingResult
|
|
9
|
-
* @typedef {import('@appium/opencv').OccurrenceResult & Visualized} OccurrenceResult
|
|
10
|
-
* @typedef {import('@appium/opencv').SimilarityResult & Visualized} SimilarityResult
|
|
11
|
-
* @typedef {MatchingResult|OccurrenceResult|SimilarityResult|SimilarityResult[]} ComparisonResult
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Performs images comparison using OpenCV framework features.
|
|
16
|
-
* It is expected that both OpenCV framework and opencv4nodejs
|
|
17
|
-
* module are installed on the machine where Appium server is running.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} mode - One of possible comparison modes:
|
|
20
|
-
* matchFeatures, getSimilarity, matchTemplate
|
|
21
|
-
* @param {string|Buffer} firstImage - Base64-encoded image file.
|
|
22
|
-
* All image formats, that OpenCV library itself accepts, are supported.
|
|
23
|
-
* @param {string|Buffer} secondImage - Base64-encoded image file.
|
|
24
|
-
* All image formats, that OpenCV library itself accepts, are supported.
|
|
25
|
-
* @param {import('@appium/opencv').MatchingOptions
|
|
26
|
-
* |import('@appium/opencv').SimilarityOptions
|
|
27
|
-
* |import('@appium/opencv').OccurrenceOptions} [options={}] - The content of this dictionary depends
|
|
28
|
-
* on the actual `mode` value. See the documentation on `@appium/support`
|
|
29
|
-
* module for more details.
|
|
30
|
-
* @returns {Promise<ComparisonResult>} The content of the resulting dictionary depends
|
|
31
|
-
* on the actual `mode` and `options` values. See the documentation on
|
|
32
|
-
* `@appium/support` module for more details.
|
|
33
|
-
* @throws {Error} If required OpenCV modules are not installed or
|
|
34
|
-
* if `mode` value is incorrect or if there was an unexpected issue while
|
|
35
|
-
* matching the images.
|
|
36
|
-
*/
|
|
37
|
-
async function compareImages(mode, firstImage, secondImage, options = {}) {
|
|
38
|
-
const img1 = Buffer.isBuffer(firstImage) ? firstImage : Buffer.from(firstImage, 'base64');
|
|
39
|
-
const img2 = Buffer.isBuffer(secondImage) ? secondImage : Buffer.from(secondImage, 'base64');
|
|
40
|
-
let result;
|
|
41
|
-
switch (_.toLower(mode)) {
|
|
42
|
-
case MATCH_FEATURES_MODE.toLowerCase():
|
|
43
|
-
try {
|
|
44
|
-
result = await getImagesMatches(
|
|
45
|
-
img1, img2, /** @type {import('@appium/opencv').MatchingOptions} */(options)
|
|
46
|
-
);
|
|
47
|
-
} catch {
|
|
48
|
-
// might throw if no matches
|
|
49
|
-
result = /** @type {import('@appium/opencv').MatchingResult} */({count: 0});
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case GET_SIMILARITY_MODE.toLowerCase():
|
|
53
|
-
result = await getImagesSimilarity(
|
|
54
|
-
img1, img2, /** @type {import('@appium/opencv').SimilarityOptions} */(options));
|
|
55
|
-
break;
|
|
56
|
-
case MATCH_TEMPLATE_MODE.toLowerCase(): {
|
|
57
|
-
const opts = /** @type {import('@appium/opencv').OccurrenceOptions} */(options);
|
|
58
|
-
// firstImage/img1 is the full image and secondImage/img2 is the partial one
|
|
59
|
-
result = await getImageOccurrence(
|
|
60
|
-
img1, img2, opts
|
|
61
|
-
);
|
|
62
|
-
if (opts.multiple && result.multiple) {
|
|
63
|
-
return result.multiple.map(convertVisualizationToBase64);
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
default:
|
|
68
|
-
throw new errors.InvalidArgumentError(
|
|
69
|
-
`'${mode}' images comparison mode is unknown. ` +
|
|
70
|
-
`Only ${JSON.stringify([
|
|
71
|
-
MATCH_FEATURES_MODE,
|
|
72
|
-
GET_SIMILARITY_MODE,
|
|
73
|
-
MATCH_TEMPLATE_MODE,
|
|
74
|
-
])} modes are supported.`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
return convertVisualizationToBase64(result);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* base64 encodes the visualization part of the result
|
|
82
|
-
* (if necessary)
|
|
83
|
-
*
|
|
84
|
-
* @param {Partial<{visualization: Buffer|null}>} element - occurrence result
|
|
85
|
-
* @returns {any} I know this looks ugly from the typing perspective
|
|
86
|
-
**/
|
|
87
|
-
function convertVisualizationToBase64(element) {
|
|
88
|
-
return Buffer.isBuffer(element.visualization)
|
|
89
|
-
? {
|
|
90
|
-
...(element),
|
|
91
|
-
visualization: element.visualization.toString('base64')
|
|
92
|
-
}
|
|
93
|
-
: element;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export {compareImages};
|
package/lib/constants.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
});
|