@applitools/driver 1.8.7 → 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 +9 -3
- package/dist/driver.js +4 -0
- package/dist/element.js +25 -2
- 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
|
@@ -470,6 +470,7 @@ class Context {
|
|
|
470
470
|
async getRegionInViewport(region) {
|
|
471
471
|
var _a, _b;
|
|
472
472
|
let currentContext = this;
|
|
473
|
+
this._logger.log('Converting context region to viewport region', region);
|
|
473
474
|
if (region)
|
|
474
475
|
region = utils.geometry.offsetNegative(region, await currentContext.getInnerOffset());
|
|
475
476
|
else
|
|
@@ -478,9 +479,14 @@ class Context {
|
|
|
478
479
|
const contextRegion = await currentContext.getClientRegion();
|
|
479
480
|
// const contextScrollingRegion = await currentContext.getScrollingRegion()
|
|
480
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 };
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
482
|
+
// TODO revisit
|
|
483
|
+
if ((utils.geometry.contains(contextRegion, region) || !currentContext.isMain) &&
|
|
484
|
+
!utils.geometry.equals(contextRegion, region)) {
|
|
485
|
+
this._logger.log('Intersecting context region', region, 'with context region', contextRegion);
|
|
486
|
+
region = utils.geometry.intersect(contextRegion, utils.geometry.offset(region, contextRegion));
|
|
487
|
+
// region = utils.geometry.intersect(contextScrollingRegion, region)
|
|
488
|
+
region = utils.geometry.offsetNegative(region, parentContextInnerOffset);
|
|
489
|
+
}
|
|
484
490
|
currentContext = currentContext.parent;
|
|
485
491
|
}
|
|
486
492
|
return region;
|
package/dist/driver.js
CHANGED
|
@@ -191,6 +191,10 @@ class Driver {
|
|
|
191
191
|
if (barsSize.navigationBarHeight / this.pixelRatio < displaySize.height) {
|
|
192
192
|
this._driverInfo.navigationBarHeight = Math.max((_u = this._driverInfo.navigationBarHeight) !== null && _u !== void 0 ? _u : 0, barsSize.navigationBarHeight);
|
|
193
193
|
}
|
|
194
|
+
else {
|
|
195
|
+
// if navigation bar height is bigger then display height he can use it to reset display height
|
|
196
|
+
displaySize.height = barsSize.navigationBarHeight / this.pixelRatio;
|
|
197
|
+
}
|
|
194
198
|
// bar heights have to be scaled on android
|
|
195
199
|
(_3 = this._driverInfo).statusBarHeight && (_3.statusBarHeight = this._driverInfo.statusBarHeight / this.pixelRatio);
|
|
196
200
|
(_4 = this._driverInfo).navigationBarHeight && (_4.navigationBarHeight = this._driverInfo.navigationBarHeight / this.pixelRatio);
|
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;
|
|
@@ -121,8 +141,11 @@ class Element {
|
|
|
121
141
|
const region = await this._spec.getElementRegion(this.driver.target, this.target);
|
|
122
142
|
this._logger.log('Extracted native region', region);
|
|
123
143
|
const normalizedRegion = await this.driver.normalizeRegion(region);
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
// if element is a child of scrolling element, then region location should be adjusted
|
|
145
|
+
const scrollingElement = await this.context.getScrollingElement();
|
|
146
|
+
return (await (scrollingElement === null || scrollingElement === void 0 ? void 0 : scrollingElement.contains(this)))
|
|
147
|
+
? utils.geometry.offset(normalizedRegion, await scrollingElement.getScrollOffset())
|
|
148
|
+
: normalizedRegion;
|
|
126
149
|
}
|
|
127
150
|
});
|
|
128
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 {};
|