forked from applitools/Eyes.Selenium.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementArrayFinderWrapper.js
More file actions
74 lines (62 loc) · 2.5 KB
/
Copy pathElementArrayFinderWrapper.js
File metadata and controls
74 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
63
64
65
66
67
68
69
70
71
72
73
74
/*
---
name: ElementArrayFinderWrapper
description: Wraps Protractor's ElementArrayFinder to make sure we return our own Web Element.
---
*/
(function () {
"use strict";
var EyesUtils = require('eyes.utils'),
EyesRemoteWebElement = require('./EyesRemoteWebElement'),
ElementFinderWrapper = require('./ElementFinderWrapper');
var GeneralUtils = EyesUtils.GeneralUtils;
// function in ElementArrayFinder that return a new ElementFinder and therefore we must wrap and return our own
var ELEMENT_ARRAY_FINDER_TO_ELEMENT_FINDER_FUNCTIONS = ['get', 'first', 'last'];
/**
* Wrapper for ElementArrayFinder object from Protractor
*
* @param {ElementArrayFinder} arrayFinder
* @param {EyesWebDriver} eyesDriver
* @param {Logger} logger
* @constructor
**/
function ElementArrayFinderWrapper(arrayFinder, eyesDriver, logger) {
GeneralUtils.mixin(this, arrayFinder);
this._logger = logger;
this._eyesDriver = eyesDriver;
this._arrayFinder = arrayFinder;
var that = this;
// Wrap the functions that return objects that require pre-wrapping
ELEMENT_ARRAY_FINDER_TO_ELEMENT_FINDER_FUNCTIONS.forEach(function (fnName) {
that[fnName] = function () {
return new ElementFinderWrapper(that._arrayFinder[fnName].apply(that._arrayFinder, arguments), that._eyesDriver, that._logger);
};
});
// Patch this internal function.
var originalFn = that._arrayFinder.asElementFinders_;
that._arrayFinder.asElementFinders_ = function () {
return originalFn.apply(that._arrayFinder).then(function (arr) {
var list = [];
arr.forEach(function (finder) {
list.push(new ElementFinderWrapper(finder, that._eyesDriver, that._logger));
});
return list;
});
}
}
/**
* Wrap the getWebElements function
*
* @returns {EyesRemoteWebElement[]}
*/
ElementArrayFinderWrapper.prototype.getWebElements = function () {
var that = this;
that._logger.verbose("ElementArrayFinderWrapper:getWebElements - called");
var res = [];
that._arrayFinder.getWebElements.apply(that._arrayFinder).forEach(function (el) {
res.push(new EyesRemoteWebElement(el, that._eyesDriver, that._logger));
});
return res;
};
exports.ElementArrayFinderWrapper = ElementArrayFinderWrapper;
}());