factor out image element registration to helper function
...so the function can be used by other drivers / plugins
MODIFY
lib/basedriver/commands/find.js
lib/basedriver/commands/find.js
@@ -3,7 +3,6 @@ import { logger, imageUtil } from 'appium-support';
import _ from 'lodash';
import { errors } from '../../..';
import { MATCH_TEMPLATE_MODE } from './images';
-import { W3C_ELEMENT_KEY, MJSONWP_ELEMENT_KEY } from '../../protocol/protocol';
import { ImageElement, DEFAULT_TEMPLATE_IMAGE_SCALE } from '../image-element';
@@ -285,9 +284,8 @@ helpers.findByImage = async function findByImage (b64Template, {
return imgEl;
}
- this._imgElCache.set(imgEl.id, imgEl);
- const protoKey = this.isW3CProtocol() ? W3C_ELEMENT_KEY : MJSONWP_ELEMENT_KEY;
- const protocolEl = imgEl.asElement(protoKey);
+ const protocolEl = this.registerImageElement(imgEl);
+
return multiple ? [protocolEl] : protocolEl;
};

MODIFY
lib/basedriver/driver.js
lib/basedriver/driver.js
@@ -10,6 +10,7 @@ import B from 'bluebird';
import _ from 'lodash';
import { util } from 'appium-support';
import { ImageElement, makeImageElementCache, getImgElFromArgs } from './image-element';
+import { W3C_ELEMENT_KEY, MJSONWP_ELEMENT_KEY } from '../protocol/protocol';
B.config({
@@ -477,6 +478,12 @@ class BaseDriver extends Protocol {
getManagedDrivers () {
return this.managedDrivers;
}
+
+ registerImageElement (imgEl) {
+ this._imgElCache.set(imgEl.id, imgEl);
+ const protoKey = this.isW3CProtocol() ? W3C_ELEMENT_KEY : MJSONWP_ELEMENT_KEY;
+ return imgEl.asElement(protoKey);
+ }
}
BaseDriver.DRIVER_PROTOCOL = {

factor out image element registration to helper function (#312)

...so the function can be used by other drivers / plugins