@applitools/driver
Advanced tools
Comparing version
@@ -482,3 +482,5 @@ "use strict"; | ||
const parentContextInnerOffset = (_b = (await ((_a = currentContext.parent) === null || _a === void 0 ? void 0 : _a.getInnerOffset()))) !== null && _b !== void 0 ? _b : { x: 0, y: 0 }; | ||
if (utils.geometry.contains(contextRegion, region) && !utils.geometry.equals(contextRegion, region)) { | ||
// TODO revisit | ||
if ((utils.geometry.contains(contextRegion, region) || !currentContext.isMain) && | ||
!utils.geometry.equals(contextRegion, region)) { | ||
this._logger.log('Intersecting context region', region, 'with context region', contextRegion); | ||
@@ -485,0 +487,0 @@ region = utils.geometry.intersect(contextRegion, utils.geometry.offset(region, contextRegion)); |
@@ -100,2 +100,22 @@ "use strict"; | ||
} | ||
async contains(innerElement) { | ||
const contains = await this.withRefresh(async () => { | ||
innerElement = innerElement instanceof Element ? innerElement.target : innerElement; | ||
if (this.driver.isWeb) { | ||
this._logger.log('Checking if web element with selector', this.selector, 'contains element', innerElement); | ||
return false; // TODO implement a s snipped for web | ||
} | ||
else { | ||
this._logger.log('Checking if native element with selector', this.selector, 'contains element', innerElement); | ||
// appium doesn't have a way to check if an element is contained in another element, so juristic applied | ||
if (await this.equals(innerElement)) | ||
return false; | ||
// if inner element region is located contained in the this element region, then it is contained | ||
const region = await this._spec.getElementRegion(this.driver.target, this.target); | ||
const innerRegion = await this._spec.getElementRegion(this.driver.target, innerElement); | ||
return utils.geometry.contains(region, innerRegion); | ||
} | ||
}); | ||
return contains; | ||
} | ||
async init(context) { | ||
@@ -127,9 +147,5 @@ this._context = context; | ||
const scrollingElement = await this.context.getScrollingElement(); | ||
if (scrollingElement) { | ||
const scrollingRegion = await this._spec.getElementRegion(this.driver.target, scrollingElement.target); | ||
if (utils.geometry.contains(scrollingRegion, region) && !(await this.equals(scrollingElement))) { | ||
return utils.geometry.offset(normalizedRegion, await scrollingElement.getScrollOffset()); | ||
} | ||
} | ||
return normalizedRegion; | ||
return (await (scrollingElement === null || scrollingElement === void 0 ? void 0 : scrollingElement.contains(this))) | ||
? utils.geometry.offset(normalizedRegion, await scrollingElement.getScrollOffset()) | ||
: normalizedRegion; | ||
} | ||
@@ -136,0 +152,0 @@ }); |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = void 0; | ||
exports.withFastCache = exports.splitSelector = exports.transformSelector = exports.isSelector = exports.isCommonSelector = void 0; | ||
const utils = __importStar(require("@applitools/utils")); | ||
@@ -83,1 +83,22 @@ function isCommonSelector(spec, selector) { | ||
exports.splitSelector = splitSelector; | ||
function withFastCache(spec) { | ||
const cache = new Map(); | ||
return Object.entries(spec).reduce((spec, [name, command]) => { | ||
spec[name] = (...args) => { | ||
const value = cache.get(command); | ||
if ((value === null || value === void 0 ? void 0 : value.args.length) === args.length && value.args.every((arg, index) => arg === args[index])) { | ||
return value.result; | ||
} | ||
else { | ||
cache.delete(command); | ||
} | ||
const result = command(...args); | ||
if (!(result instanceof Promise)) | ||
return result; | ||
cache.set(command, { args, result }); | ||
return result.finally(() => setImmediate(() => cache.delete(command))); | ||
}; | ||
return spec; | ||
}, {}); | ||
} | ||
exports.withFastCache = withFastCache; |
{ | ||
"name": "@applitools/driver", | ||
"version": "1.8.9", | ||
"version": "1.8.10", | ||
"description": "Applitools universal framework wrapper", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -34,2 +34,3 @@ import type * as types from '@applitools/types'; | ||
equals(element: Element<TDriver, TContext, TElement, TSelector> | TElement): Promise<boolean>; | ||
contains(innerElement: Element<TDriver, TContext, TElement, TSelector> | TElement): Promise<boolean>; | ||
init(context: Context<TDriver, TContext, TElement, TSelector>): Promise<this>; | ||
@@ -36,0 +37,0 @@ getRegion(): Promise<types.Region>; |
@@ -20,2 +20,3 @@ import type * as types from '@applitools/types'; | ||
}; | ||
export declare function withFastCache<TSpecDriver extends types.SpecDriver<unknown, unknown, unknown, unknown>>(spec: TSpecDriver): TSpecDriver; | ||
export {}; |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
198082
1.13%3080
1.35%