@applitools/driver 1.8.9 → 1.8.10
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/dist/context.js +3 -1
- package/dist/element.js +23 -7
- package/dist/spec-utils.js +22 -1
- package/package.json +1 -1
- package/types/element.d.ts +1 -0
- package/types/spec-utils.d.ts +1 -0
package/dist/context.js
CHANGED
|
@@ -479,7 +479,9 @@ class Context {
|
|
|
479
479
|
const contextRegion = await currentContext.getClientRegion();
|
|
480
480
|
// const contextScrollingRegion = await currentContext.getScrollingRegion()
|
|
481
481
|
const parentContextInnerOffset = (_b = (await ((_a = currentContext.parent) === null || _a === void 0 ? void 0 : _a.getInnerOffset()))) !== null && _b !== void 0 ? _b : { x: 0, y: 0 };
|
|
482
|
-
|
|
482
|
+
// TODO revisit
|
|
483
|
+
if ((utils.geometry.contains(contextRegion, region) || !currentContext.isMain) &&
|
|
484
|
+
!utils.geometry.equals(contextRegion, region)) {
|
|
483
485
|
this._logger.log('Intersecting context region', region, 'with context region', contextRegion);
|
|
484
486
|
region = utils.geometry.intersect(contextRegion, utils.geometry.offset(region, contextRegion));
|
|
485
487
|
// region = utils.geometry.intersect(contextScrollingRegion, region)
|
package/dist/element.js
CHANGED
|
@@ -97,6 +97,26 @@ class Element {
|
|
|
97
97
|
return this._spec.isEqualElements(this.context.target, this.target, element);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
async contains(innerElement) {
|
|
101
|
+
const contains = await this.withRefresh(async () => {
|
|
102
|
+
innerElement = innerElement instanceof Element ? innerElement.target : innerElement;
|
|
103
|
+
if (this.driver.isWeb) {
|
|
104
|
+
this._logger.log('Checking if web element with selector', this.selector, 'contains element', innerElement);
|
|
105
|
+
return false; // TODO implement a s snipped for web
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this._logger.log('Checking if native element with selector', this.selector, 'contains element', innerElement);
|
|
109
|
+
// appium doesn't have a way to check if an element is contained in another element, so juristic applied
|
|
110
|
+
if (await this.equals(innerElement))
|
|
111
|
+
return false;
|
|
112
|
+
// if inner element region is located contained in the this element region, then it is contained
|
|
113
|
+
const region = await this._spec.getElementRegion(this.driver.target, this.target);
|
|
114
|
+
const innerRegion = await this._spec.getElementRegion(this.driver.target, innerElement);
|
|
115
|
+
return utils.geometry.contains(region, innerRegion);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return contains;
|
|
119
|
+
}
|
|
100
120
|
async init(context) {
|
|
101
121
|
this._context = context;
|
|
102
122
|
this._logger = context._logger;
|
|
@@ -123,13 +143,9 @@ class Element {
|
|
|
123
143
|
const normalizedRegion = await this.driver.normalizeRegion(region);
|
|
124
144
|
// if element is a child of scrolling element, then region location should be adjusted
|
|
125
145
|
const scrollingElement = await this.context.getScrollingElement();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return utils.geometry.offset(normalizedRegion, await scrollingElement.getScrollOffset());
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return normalizedRegion;
|
|
146
|
+
return (await (scrollingElement === null || scrollingElement === void 0 ? void 0 : scrollingElement.contains(this)))
|
|
147
|
+
? utils.geometry.offset(normalizedRegion, await scrollingElement.getScrollOffset())
|
|
148
|
+
: normalizedRegion;
|
|
133
149
|
}
|
|
134
150
|
});
|
|
135
151
|
this._logger.log('Extracted region', region);
|
package/dist/spec-utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = void 0;
|
|
26
|
+
exports.withFastCache = exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = void 0;
|
|
27
27
|
const utils = __importStar(require("@applitools/utils"));
|
|
28
28
|
function isCommonSelector(spec, selector) {
|
|
29
29
|
return (utils.types.isPlainObject(selector) &&
|
|
@@ -79,3 +79,24 @@ function splitSelector(spec, selector) {
|
|
|
79
79
|
return { contextSelectors, elementSelector };
|
|
80
80
|
}
|
|
81
81
|
exports.splitSelector = splitSelector;
|
|
82
|
+
function withFastCache(spec) {
|
|
83
|
+
const cache = new Map();
|
|
84
|
+
return Object.entries(spec).reduce((spec, [name, command]) => {
|
|
85
|
+
spec[name] = (...args) => {
|
|
86
|
+
const value = cache.get(command);
|
|
87
|
+
if ((value === null || value === void 0 ? void 0 : value.args.length) === args.length && value.args.every((arg, index) => arg === args[index])) {
|
|
88
|
+
return value.result;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
cache.delete(command);
|
|
92
|
+
}
|
|
93
|
+
const result = command(...args);
|
|
94
|
+
if (!(result instanceof Promise))
|
|
95
|
+
return result;
|
|
96
|
+
cache.set(command, { args, result });
|
|
97
|
+
return result.finally(() => setImmediate(() => cache.delete(command)));
|
|
98
|
+
};
|
|
99
|
+
return spec;
|
|
100
|
+
}, {});
|
|
101
|
+
}
|
|
102
|
+
exports.withFastCache = withFastCache;
|
package/package.json
CHANGED
package/types/element.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class Element<TDriver, TContext, TElement, TSelector> {
|
|
|
31
31
|
get driver(): import("./driver").Driver<TDriver, TContext, TElement, TSelector>;
|
|
32
32
|
get isRef(): boolean;
|
|
33
33
|
equals(element: Element<TDriver, TContext, TElement, TSelector> | TElement): Promise<boolean>;
|
|
34
|
+
contains(innerElement: Element<TDriver, TContext, TElement, TSelector> | TElement): Promise<boolean>;
|
|
34
35
|
init(context: Context<TDriver, TContext, TElement, TSelector>): Promise<this>;
|
|
35
36
|
getRegion(): Promise<types.Region>;
|
|
36
37
|
getClientRegion(): Promise<types.Region>;
|
package/types/spec-utils.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export declare function splitSelector<TSelector>(spec: Pick<types.SpecDriver<unk
|
|
|
17
17
|
contextSelectors: types.Selector<TSelector>[];
|
|
18
18
|
elementSelector: types.Selector<TSelector>;
|
|
19
19
|
};
|
|
20
|
+
export declare function withFastCache<TSpecDriver extends types.SpecDriver<unknown, unknown, unknown, unknown>>(spec: TSpecDriver): TSpecDriver;
|
|
20
21
|
export {};
|