Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@applitools/driver

Package Overview
Dependencies
Maintainers
23
Versions
216
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/driver - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

dist/fake/mock-driver.js

26

.bongo/dry-run/package-lock.json

@@ -7,25 +7,25 @@ {

"version": "file:../dry-run.tgz",
"integrity": "sha512-N5y0yZDNbHa5IBxtT8teYlLYzxDPHZhuti01cdsiDKJb0EIaBTHyMIVrJnYT/Doi3tCG+JUdxtKZeVQWatfYMQ==",
"integrity": "sha512-zRt9c44ilW/TBn1wHGgoORJ3ye2xWnKfoiwAIqeUKA5q7GxRy1ec3qu6v+7W6Rj4QIj+W/49r6TO773cIMoQPQ==",
"requires": {
"@applitools/snippets": "2.1.6",
"@applitools/types": "1.0.12",
"@applitools/utils": "1.2.2"
"@applitools/snippets": "2.1.7",
"@applitools/types": "1.0.13",
"@applitools/utils": "1.2.3"
}
},
"@applitools/snippets": {
"version": "2.1.6",
"resolved": "https://registry.npmjs.org/@applitools/snippets/-/snippets-2.1.6.tgz",
"integrity": "sha512-0TIUBzPWyYNvCoKkpZEAPWh4K0ceGkB+OFuquinCHDoV1yjQr63b9jglNNQkCbg3cYtL3VfF6VEi0vyHRF6xrg=="
"version": "2.1.7",
"resolved": "https://registry.npmjs.org/@applitools/snippets/-/snippets-2.1.7.tgz",
"integrity": "sha512-Tr4Gj7Qov/oPy+8WI4oVmmubxqpOzr8P3Wjzpl6rA57xKLg6/TiIg5oZNb4+jEmO2ShjNYLaEwRWHl7kPgb4fw=="
},
"@applitools/types": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/@applitools/types/-/types-1.0.12.tgz",
"integrity": "sha512-CM5w3gb9lkNL7yOT3WLrCF1T/21yWH/mw+v79ePvzByizw2qWGJwJImRC9Od0tnIg3QMZI5xrV72b32OUcZvbA=="
"version": "1.0.13",
"resolved": "https://registry.npmjs.org/@applitools/types/-/types-1.0.13.tgz",
"integrity": "sha512-LypJhuCxs0/FafnQoV7XDUuDAoF73Q16ZwbUIUwzKPYyO42oAuAKq1UaO5uJVOG+m07aFXb7RpbYMQZ8MuUQGg=="
},
"@applitools/utils": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@applitools/utils/-/utils-1.2.2.tgz",
"integrity": "sha512-SyHY41J+hkZR9gma/M8gjbJXLXeLoVS5DQVYd/RinzWAq62Yvg9eA97+8oHDl8s+6ELK6wMcs4yajjqCPdpF0A=="
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@applitools/utils/-/utils-1.2.3.tgz",
"integrity": "sha512-MZXsrzeHTvjFLzpfyKRDUmZWzNxH3gWd3reqYf+1kYimALKB3CO82VDNmkaGJykrRbxEP03Yqha7fHJj9eKslQ=="
}
}
}

@@ -6,2 +6,9 @@ # Change Log

## 1.2.0 - 2021/9/9
- add support for deep selectors
- updated to @applitools/snippets@2.1.7 (from 2.1.6)
- updated to @applitools/types@1.0.13 (from 1.0.12)
- updated to @applitools/utils@1.2.3 (from 1.2.2)
## 1.1.5 - 2021/9/6

@@ -8,0 +15,0 @@

@@ -24,2 +24,3 @@ "use strict";

const utils = __importStar(require("@applitools/utils"));
const utils_1 = require("./utils");
const element_1 = require("./element");

@@ -34,2 +35,3 @@ const snippets = require('@applitools/snippets');

this._spec = options.spec;
this._utils = utils_1.makeSpecUtils(options.spec);
if (options.logger)

@@ -45,3 +47,3 @@ this._logger = options.logger;

}
if (this.isReference(options.reference)) {
if (this._isReference(options.reference)) {
if (options.reference instanceof Context)

@@ -67,2 +69,10 @@ return options.reference;

}
_isReference(reference) {
return (reference instanceof Context ||
utils.types.isInteger(reference) ||
utils.types.isString(reference) ||
reference instanceof element_1.Element ||
this._spec.isElement(reference) ||
this._utils.isSelector(reference));
}
get target() {

@@ -98,10 +108,2 @@ return this._target;

}
isReference(reference) {
return (reference instanceof Context ||
utils.types.isInteger(reference) ||
utils.types.isString(reference) ||
reference instanceof element_1.Element ||
this._spec.isElement(reference) ||
this._spec.isSelector(reference));
}
async init() {

@@ -122,3 +124,3 @@ if (this.isInitialized)

}
else if (utils.types.isString(this._reference) || this._spec.isSelector(this._reference)) {
else if (utils.types.isString(this._reference) || this._utils.isSelector(this._reference)) {
if (utils.types.isString(this._reference)) {

@@ -130,3 +132,3 @@ this._logger.log('Getting context element by name or id', this._reference);

}
if (!this._element && this._spec.isSelector(this._reference)) {
if (!this._element && this._utils.isSelector(this._reference)) {
this._logger.log('Getting context element by selector', this._reference);

@@ -191,3 +193,3 @@ this._element = await this.parent.element(this._reference);

}
else if (this.isReference(reference)) {
else if (this._isReference(reference)) {
return new Context({ spec: this._spec, parent: this, driver: this.driver, reference, logger: this._logger });

@@ -207,27 +209,34 @@ }

}
async element(selectorOrElement) {
if (this._spec.isSelector(selectorOrElement)) {
async element(elementOrSelector) {
var _a;
if (this._spec.isElement(elementOrSelector)) {
return new element_1.Element({ spec: this._spec, context: this, element: elementOrSelector, logger: this._logger });
}
else if (this._utils.isSelector(elementOrSelector)) {
if (this.isRef) {
return new element_1.Element({ spec: this._spec, context: this, selector: selectorOrElement, logger: this._logger });
return new element_1.Element({ spec: this._spec, context: this, selector: elementOrSelector, logger: this._logger });
}
await this.focus();
let rootElement = null;
let selector = selectorOrElement;
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) {
const element = await this._spec.findElement(this.target, selector, rootElement);
if (!element)
const selectors = this._utils.splitSelector(elementOrSelector);
const contextSelectors = selectors.slice(0, -1);
const elementSelector = selectors[selectors.length - 1];
let context = this;
for (const contextSelector of contextSelectors) {
context = await context
.context(contextSelector)
.then(context => context.focus())
.catch(() => null);
if (!context)
return null;
rootElement = await this.execute(snippets.getShadowRoot, element);
if (!rootElement)
return null;
selector = selector.shadow;
}
const element = await this._spec.findElement(this.target, selector, rootElement);
const { root, selector } = ((_a = this.driver.features) === null || _a === void 0 ? void 0 : _a.shadowSelector)
? { root: null, selector: elementSelector }
: await this._utils.findRootElement(context.target, elementSelector);
if (!root && selector !== elementSelector)
return null;
const element = await this._spec.findElement(context.target, this._utils.transformSelector(selector), root);
return element
? new element_1.Element({ spec: this._spec, context: this, element, selector: selectorOrElement, logger: this._logger })
? new element_1.Element({ spec: this._spec, context, element, selector: elementSelector, logger: this._logger })
: null;
}
else if (this._spec.isElement(selectorOrElement)) {
return new element_1.Element({ spec: this._spec, context: this, element: selectorOrElement, logger: this._logger });
}
else {

@@ -237,26 +246,36 @@ throw new TypeError('Cannot find element using argument of unknown type!');

}
async elements(selectorOrElement) {
if (this._spec.isSelector(selectorOrElement)) {
async elements(elementOrSelector) {
var _a;
if (this._spec.isElement(elementOrSelector)) {
return [new element_1.Element({ spec: this._spec, context: this, element: elementOrSelector, logger: this._logger })];
}
else if (this._utils.isSelector(elementOrSelector)) {
if (this.isRef) {
return [new element_1.Element({ spec: this._spec, context: this, selector: selectorOrElement, logger: this._logger })];
return [new element_1.Element({ spec: this._spec, context: this, selector: elementOrSelector, logger: this._logger })];
}
await this.focus();
let rootElement = null;
let selector = selectorOrElement;
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) {
const element = await this._spec.findElement(this.target, selector, rootElement);
if (!element)
const selectors = this._utils.splitSelector(elementOrSelector);
const contextSelectors = selectors.slice(0, -1);
const elementSelector = selectors[selectors.length - 1];
let context = this;
for (const contextSelector of contextSelectors) {
context = await context
.context(contextSelector)
.then(context => context.focus())
.catch(() => null);
if (!context)
return [];
rootElement = await this.execute(snippets.getShadowRoot, element);
if (!rootElement)
return [];
selector = selector.shadow;
}
const elements = await this._spec.findElements(this.target, selector, rootElement);
const { root, selector } = ((_a = this.driver.features) === null || _a === void 0 ? void 0 : _a.shadowSelector)
? { root: null, selector: elementSelector }
: await this._utils.findRootElement(context.target, elementSelector);
if (!root && selector !== elementSelector)
return [];
const elements = await this._spec.findElements(context.target, this._utils.transformSelector(selector), root);
return elements.map((element, index) => {
return new element_1.Element({
spec: this._spec,
context: this,
context,
element,
selector: selectorOrElement,
selector: elementSelector,
index,

@@ -267,5 +286,2 @@ logger: this._logger,

}
else if (this._spec.isElement(selectorOrElement)) {
return [new element_1.Element({ spec: this._spec, context: this, element: selectorOrElement, logger: this._logger })];
}
else {

@@ -272,0 +288,0 @@ throw new TypeError('Cannot find elements using argument of unknown type!');

@@ -25,2 +25,3 @@ "use strict";

const context_1 = require("./context");
const utils_1 = require("./utils");
const user_agent_1 = require("./user-agent");

@@ -35,2 +36,3 @@ const snippets = require('@applitools/snippets');

this._spec = options.spec;
this._utils = utils_1.makeSpecUtils(options.spec);
if (options.logger)

@@ -61,2 +63,6 @@ this._logger = options.logger;

}
get features() {
var _a;
return (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.features;
}
get deviceName() {

@@ -154,2 +160,3 @@ var _a;

const spec = this._spec;
const utils = this._utils;
let currentContext = this.currentContext.target;

@@ -187,3 +194,3 @@ let contextInfo = await getContextInfo(currentContext);

if (contextInfo.selector) {
const contextElement = await spec.findElement(context, { type: 'xpath', selector: contextInfo.selector });
const contextElement = await spec.findElement(context, utils.transformSelector({ type: 'xpath', selector: contextInfo.selector }));
if (contextElement)

@@ -196,3 +203,3 @@ return contextElement;

const childContext = await spec.childContext(context, childContextInfo.contextElement);
const contentDocument = await spec.findElement(childContext, { type: 'css', selector: 'html' });
const contentDocument = await spec.findElement(childContext, utils.transformSelector('html'));
const isWantedContext = await isEqualElements(childContext, contentDocument, contextInfo.documentElement);

@@ -205,3 +212,3 @@ await spec.parentContext(childContext);

async function findContextPath(context, contextInfo, contextPath = []) {
const contentDocument = await spec.findElement(context, { type: 'css', selector: 'html' });
const contentDocument = await spec.findElement(context, utils.transformSelector('html'));
if (await isEqualElements(context, contentDocument, contextInfo.documentElement)) {

@@ -208,0 +215,0 @@ return contextPath;

@@ -24,2 +24,3 @@ "use strict";

const utils = __importStar(require("@applitools/utils"));
const utils_1 = require("./utils");
const snippets = require('@applitools/snippets');

@@ -33,2 +34,3 @@ class Element {

this._spec = options.spec;
this._utils = utils_1.makeSpecUtils(options.spec);
if (options.context)

@@ -44,3 +46,3 @@ this._context = options.context;

}
else if (this._spec.isSelector(options.selector)) {
else if (this._utils.isSelector(options.selector)) {
this._selector = options.selector;

@@ -47,0 +49,0 @@ }

@@ -9,8 +9,23 @@ "use strict";

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fake = void 0;
__exportStar(require("./driver"), exports);
__exportStar(require("./context"), exports);
__exportStar(require("./driver"), exports);
__exportStar(require("./element"), exports);
__exportStar(require("./fake/mock-driver"), exports);
exports.fake = __importStar(require("./fake/spec-driver"));
{
"name": "@applitools/driver",
"version": "1.1.5",
"version": "1.2.0",
"description": "Applitools universal framework wrapper",

@@ -47,8 +47,8 @@ "keywords": [

"dependencies": {
"@applitools/snippets": "2.1.6",
"@applitools/types": "1.0.12",
"@applitools/utils": "1.2.2"
"@applitools/snippets": "2.1.7",
"@applitools/types": "1.0.13",
"@applitools/utils": "1.2.3"
},
"devDependencies": {
"@applitools/sdk-release-kit": "0.13.2",
"@applitools/sdk-release-kit": "0.13.3",
"@types/mocha": "^9.0.0",

@@ -55,0 +55,0 @@ "@types/node": "^16.3.3",

import type * as types from '@applitools/types'
import type {Driver} from './driver'
import type {SpecUtils} from './utils'
import * as utils from '@applitools/utils'
import {makeSpecUtils} from './utils'
import {Element} from './element'

@@ -11,3 +13,3 @@

| TElement
| TSelector
| types.Selector<TSelector>
| string

@@ -41,3 +43,15 @@ | number

private _logger: any
private _utils: SpecUtils<TDriver, TContext, TElement, TSelector>
private _isReference(reference: any): reference is ContextReference<TDriver, TContext, TElement, TSelector> {
return (
reference instanceof Context ||
utils.types.isInteger(reference) ||
utils.types.isString(reference) ||
reference instanceof Element ||
this._spec.isElement(reference) ||
this._utils.isSelector(reference)
)
}
protected readonly _spec: types.SpecDriver<TDriver, TContext, TElement, TSelector>

@@ -58,2 +72,3 @@

this._spec = options.spec
this._utils = makeSpecUtils(options.spec)

@@ -70,3 +85,3 @@ if (options.logger) this._logger = options.logger

if (this.isReference(options.reference)) {
if (this._isReference(options.reference)) {
if (options.reference instanceof Context) return options.reference

@@ -127,13 +142,2 @@ if (!options.parent) {

isReference(reference: any): reference is ContextReference<TDriver, TContext, TElement, TSelector> {
return (
reference instanceof Context ||
utils.types.isInteger(reference) ||
utils.types.isString(reference) ||
reference instanceof Element ||
this._spec.isElement(reference) ||
this._spec.isSelector(reference)
)
}
async init(): Promise<this> {

@@ -154,3 +158,3 @@ if (this.isInitialized) return this

this._element = elements[this._reference]
} else if (utils.types.isString(this._reference) || this._spec.isSelector(this._reference)) {
} else if (utils.types.isString(this._reference) || this._utils.isSelector(this._reference)) {
if (utils.types.isString(this._reference)) {

@@ -162,3 +166,3 @@ this._logger.log('Getting context element by name or id', this._reference)

}
if (!this._element && this._spec.isSelector(this._reference)) {
if (!this._element && this._utils.isSelector(this._reference)) {
this._logger.log('Getting context element by selector', this._reference)

@@ -234,3 +238,3 @@ this._element = await this.parent.element(this._reference)

return reference
} else if (this.isReference(reference)) {
} else if (this._isReference(reference)) {
return new Context({spec: this._spec, parent: this, driver: this.driver, reference, logger: this._logger})

@@ -251,26 +255,35 @@ } else if (utils.types.has(reference, 'reference')) {

async element(
selectorOrElement: types.SpecSelector<TSelector> | TElement,
elementOrSelector: TElement | types.Selector<TSelector>,
): Promise<Element<TDriver, TContext, TElement, TSelector>> {
if (this._spec.isSelector(selectorOrElement)) {
if (this._spec.isElement(elementOrSelector)) {
return new Element({spec: this._spec, context: this, element: elementOrSelector, logger: this._logger})
} else if (this._utils.isSelector(elementOrSelector)) {
if (this.isRef) {
return new Element({spec: this._spec, context: this, selector: selectorOrElement, logger: this._logger})
return new Element({spec: this._spec, context: this, selector: elementOrSelector, logger: this._logger})
}
await this.focus()
let rootElement = null
let selector = selectorOrElement
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) {
const element: TElement = await this._spec.findElement(this.target, selector, rootElement)
if (!element) return null
rootElement = await this.execute(snippets.getShadowRoot, element)
if (!rootElement) return null
selector = selector.shadow
const selectors = this._utils.splitSelector(elementOrSelector)
const contextSelectors = selectors.slice(0, -1)
const elementSelector = selectors[selectors.length - 1]
let context = this as Context<TDriver, TContext, TElement, TSelector>
for (const contextSelector of contextSelectors) {
context = await context
.context(contextSelector)
.then(context => context.focus())
.catch(() => null)
if (!context) return null
}
const element = await this._spec.findElement(this.target, selector, rootElement)
const {root, selector} = this.driver.features?.shadowSelector
? {root: null, selector: elementSelector}
: await this._utils.findRootElement(context.target, elementSelector)
if (!root && selector !== elementSelector) return null
const element = await this._spec.findElement(context.target, this._utils.transformSelector(selector), root)
return element
? new Element({spec: this._spec, context: this, element, selector: selectorOrElement, logger: this._logger})
? new Element({spec: this._spec, context, element, selector: elementSelector, logger: this._logger})
: null
} else if (this._spec.isElement(selectorOrElement)) {
return new Element({spec: this._spec, context: this, element: selectorOrElement, logger: this._logger})
} else {

@@ -282,27 +295,38 @@ throw new TypeError('Cannot find element using argument of unknown type!')

async elements(
selectorOrElement: types.SpecSelector<TSelector> | TElement,
elementOrSelector: TElement | types.Selector<TSelector>,
): Promise<Element<TDriver, TContext, TElement, TSelector>[]> {
if (this._spec.isSelector(selectorOrElement)) {
if (this._spec.isElement(elementOrSelector)) {
return [new Element({spec: this._spec, context: this, element: elementOrSelector, logger: this._logger})]
} else if (this._utils.isSelector(elementOrSelector)) {
if (this.isRef) {
return [new Element({spec: this._spec, context: this, selector: selectorOrElement, logger: this._logger})]
return [new Element({spec: this._spec, context: this, selector: elementOrSelector, logger: this._logger})]
}
await this.focus()
let rootElement = null
let selector = selectorOrElement
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) {
const element: TElement = await this._spec.findElement(this.target, selector, rootElement)
if (!element) return []
rootElement = await this.execute(snippets.getShadowRoot, element)
if (!rootElement) return []
selector = selector.shadow
const selectors = this._utils.splitSelector(elementOrSelector)
const contextSelectors = selectors.slice(0, -1)
const elementSelector = selectors[selectors.length - 1]
let context = this as Context<TDriver, TContext, TElement, TSelector>
for (const contextSelector of contextSelectors) {
context = await context
.context(contextSelector)
.then(context => context.focus())
.catch(() => null)
if (!context) return []
}
const elements = await this._spec.findElements(this.target, selector, rootElement)
const {root, selector} = this.driver.features?.shadowSelector
? {root: null, selector: elementSelector}
: await this._utils.findRootElement(context.target, elementSelector)
if (!root && selector !== elementSelector) return []
const elements = await this._spec.findElements(context.target, this._utils.transformSelector(selector), root)
return elements.map((element, index) => {
return new Element({
spec: this._spec,
context: this,
context,
element,
selector: selectorOrElement,
selector: elementSelector,
index,

@@ -312,4 +336,2 @@ logger: this._logger,

})
} else if (this._spec.isElement(selectorOrElement)) {
return [new Element({spec: this._spec, context: this, element: selectorOrElement, logger: this._logger})]
} else {

@@ -366,3 +388,3 @@ throw new TypeError('Cannot find elements using argument of unknown type!')

async setScrollingElement(
scrollingElement: Element<TDriver, TContext, TElement, TSelector> | TElement | types.SpecSelector<TSelector>,
scrollingElement: Element<TDriver, TContext, TElement, TSelector> | TElement | types.Selector<TSelector>,
): Promise<void> {

@@ -369,0 +391,0 @@ if (scrollingElement === undefined) return

import type * as types from '@applitools/types'
import type {SpecUtils} from './utils'
import * as utils from '@applitools/utils'
import {Context, ContextReference} from './context'
import {Element} from './element'
import {makeSpecUtils} from './utils'
import {parseUserAgent} from './user-agent'

@@ -17,2 +19,3 @@

private _logger: any
private _utils: SpecUtils<TDriver, TContext, TElement, TSelector>

@@ -29,2 +32,3 @@ protected readonly _spec: types.SpecDriver<TDriver, TContext, TElement, TSelector>

this._spec = options.spec
this._utils = makeSpecUtils(options.spec)

@@ -57,2 +61,5 @@ if (options.logger) this._logger = options.logger

}
get features() {
return this._driverInfo?.features
}
get deviceName(): string {

@@ -76,9 +83,9 @@ return this._driverInfo?.deviceName

}
get pixelRatio() {
get pixelRatio(): number {
return this._driverInfo.pixelRatio ?? 1
}
get statusBarHeight() {
get statusBarHeight(): number {
return this._driverInfo.statusBarHeight ?? (this.isNative ? 0 : undefined)
}
get navigationBarHeight() {
get navigationBarHeight(): number {
return this._driverInfo.navigationBarHeight ?? (this.isNative ? 0 : undefined)

@@ -153,2 +160,3 @@ }

const spec = this._spec
const utils = this._utils

@@ -190,3 +198,6 @@ let currentContext = this.currentContext.target

if (contextInfo.selector) {
const contextElement = await spec.findElement(context, {type: 'xpath', selector: contextInfo.selector})
const contextElement = await spec.findElement(
context,
utils.transformSelector({type: 'xpath', selector: contextInfo.selector}),
)
if (contextElement) return contextElement

@@ -198,3 +209,3 @@ }

const childContext = await spec.childContext(context, childContextInfo.contextElement)
const contentDocument = await spec.findElement(childContext, {type: 'css', selector: 'html'})
const contentDocument = await spec.findElement(childContext, utils.transformSelector('html'))
const isWantedContext = await isEqualElements(childContext, contentDocument, contextInfo.documentElement)

@@ -211,3 +222,3 @@ await spec.parentContext(childContext)

): Promise<TElement[]> {
const contentDocument = await spec.findElement(context, {type: 'css', selector: 'html'})
const contentDocument = await spec.findElement(context, utils.transformSelector('html'))

@@ -336,7 +347,7 @@ if (await isEqualElements(context, contentDocument, contextInfo.documentElement)) {

async element(selector: types.SpecSelector<TSelector>): Promise<Element<TDriver, TContext, TElement, TSelector>> {
async element(selector: types.Selector<TSelector>): Promise<Element<TDriver, TContext, TElement, TSelector>> {
return this.currentContext.element(selector)
}
async elements(selector: types.SpecSelector<TSelector>): Promise<Element<TDriver, TContext, TElement, TSelector>[]> {
async elements(selector: types.Selector<TSelector>): Promise<Element<TDriver, TContext, TElement, TSelector>[]> {
return this.currentContext.elements(selector)

@@ -343,0 +354,0 @@ }

import type * as types from '@applitools/types'
import type {Context} from './context'
import type {SpecUtils} from './utils'
import * as utils from '@applitools/utils'
import {makeSpecUtils} from './utils'

@@ -17,3 +19,3 @@ const snippets = require('@applitools/snippets')

private _context: Context<TDriver, TContext, TElement, TSelector>
private _selector: types.SpecSelector<TSelector>
private _selector: types.Selector<TSelector>
private _index: number

@@ -24,2 +26,3 @@ private _state: ElementState = {}

private _logger: any
private _utils: SpecUtils<TDriver, TContext, TElement, TSelector>

@@ -32,3 +35,3 @@ protected readonly _spec: types.SpecDriver<TDriver, TContext, TElement, TSelector>

context?: Context<TDriver, TContext, TElement, TSelector>
selector?: types.SpecSelector<TSelector>
selector?: types.Selector<TSelector>
index?: number

@@ -40,2 +43,3 @@ logger?: any

this._spec = options.spec
this._utils = makeSpecUtils(options.spec)

@@ -50,3 +54,3 @@ if (options.context) this._context = options.context

this._index = options.index
} else if (this._spec.isSelector(options.selector)) {
} else if (this._utils.isSelector(options.selector)) {
this._selector = options.selector

@@ -486,3 +490,3 @@ } else {

// Some frameworks could handle stale element reference error by itself or doesn't throw an error
if (this._spec.isStaleElementError(result, this.selector)) {
if (this._spec.isStaleElementError(result, this.selector as TSelector)) {
await this.refresh()

@@ -489,0 +493,0 @@ return operation()

@@ -0,3 +1,6 @@

export * from './driver'
export * from './context'
export * from './driver'
export * from './element'
export * from './fake/mock-driver'
export * as fake from './fake/spec-driver'
import assert from 'assert'
import {Driver, Context} from '../../src/index'
import {Driver, Context, MockDriver, fake} from '../../src/index'
const MockDriver = require('../fixtures/mock-driver')
const spec = require('../fixtures/spec-driver')
describe('context', () => {
let mock: any, driver: Driver<any, any, any, any>, context: Context<any, any, any, any>
let mock: MockDriver,
driver: Driver<fake.Driver, fake.Context, fake.Element, fake.Selector>,
context: Context<fake.Driver, fake.Context, fake.Element, fake.Selector>
const logger = {log: () => null as any, warn: () => null as any, error: () => null as any}

@@ -26,3 +25,3 @@

rect: {x: 1, y: 2, width: 101, height: 102},
children: [{selector: 'frame1-1--element1'}],
children: [{selector: 'frame1-1--element1', name: 'element within frame'}],
},

@@ -44,3 +43,3 @@ ],

shadow: true,
children: [{selector: 'shadow1-1--element1'}],
children: [{selector: 'shadow1-1--element1', name: 'element within shadow'}],
},

@@ -52,3 +51,3 @@ ],

])
driver = new Driver({logger, spec, driver: mock})
driver = new Driver({logger, spec: fake.spec, driver: mock})
context = driver.currentContext

@@ -91,29 +90,35 @@ })

const childContext11 = await childContext1.context('frame1-1')
await childContext11.focus()
const element = await childContext11.element('frame1-1--element1')
assert.strictEqual(element.selector, 'frame1-1--element1')
assert.strictEqual(element.target.name, 'element within frame')
})
it('element(shadow-selector)', async () => {
const selector = {
const element = await context.element({
selector: 'shadow1',
shadow: {selector: 'shadow1-1', shadow: {selector: 'shadow1-1--element1'}},
}
const element = await context.element(selector)
assert.deepStrictEqual(element.selector, selector)
})
assert.deepStrictEqual(element.target.name, 'element within shadow')
})
it('elements(non-existent)', async () => {
const selector = 'non-existent'
const element = await context.element(selector)
it('element(frame-selector)', async () => {
const element = await context.element({
selector: 'frame1',
frame: {selector: 'frame1-1', frame: {selector: 'frame1-1--element1'}},
})
assert.deepStrictEqual(element.target.name, 'element within frame')
})
it('element(non-existent)', async () => {
const element = await context.element('non-existent')
assert.strictEqual(element, null)
})
it('elements(non-existent-shadow)', async () => {
const selector = {
it('element(non-existent-shadow)', async () => {
const element = await context.element({
selector: 'shadow1',
shadow: {selector: 'shadow1-non-existent', shadow: {selector: 'shadow1-non-existent--element1'}},
}
const element = await context.element(selector)
})

@@ -123,28 +128,46 @@ assert.strictEqual(element, null)

it('element(non-existent-frame)', async () => {
const element = await context.element({
selector: 'frame1',
frame: {selector: 'frame1-non-existent', frame: {selector: 'frame1-non-existent--element1'}},
})
assert.strictEqual(element, null)
})
it('elements(selector)', async () => {
const childContext1 = await context.context('frame1')
const childContext11 = await childContext1.context('frame1-1')
const selector = 'frame1-1--element1'
const elements = await childContext11.elements(selector)
await childContext11.focus()
const elements = await childContext11.elements('frame1-1--element1')
assert.ok(Array.isArray(elements))
assert.strictEqual(elements.length, 1)
assert.strictEqual(elements[0].selector, selector)
assert.strictEqual(elements[0].target.name, 'element within frame')
})
it('elements(shadow-selector)', async () => {
const selector = {
const elements = await context.elements({
selector: 'shadow1',
shadow: {selector: 'shadow1-1', shadow: {selector: 'shadow1-1--element1'}},
}
const elements = await context.elements(selector)
})
assert.ok(Array.isArray(elements))
assert.strictEqual(elements.length, 1)
assert.deepStrictEqual(elements[0].selector, selector)
assert.strictEqual(elements[0].target.name, 'element within shadow')
})
it('elements(shadow-selector)', async () => {
const elements = await context.elements({
selector: 'frame1',
frame: {selector: 'frame1-1', frame: {selector: 'frame1-1--element1'}},
})
assert.ok(Array.isArray(elements))
assert.strictEqual(elements.length, 1)
assert.strictEqual(elements[0].target.name, 'element within frame')
})
it('elements(non-existent)', async () => {
const selector = 'non-existent'
const elements = await context.elements(selector)
const elements = await context.elements('non-existent')

@@ -156,7 +179,6 @@ assert.ok(Array.isArray(elements))

it('elements(non-existent-shadow)', async () => {
const selector = {
const elements = await context.elements({
selector: 'shadow1',
shadow: {selector: 'shadow1-non-existent', shadow: {selector: 'shadow1-non-existent--element1'}},
}
const elements = await context.elements(selector)
})

@@ -167,2 +189,12 @@ assert.ok(Array.isArray(elements))

it('elements(non-existent-frame)', async () => {
const elements = await context.elements({
selector: 'frame1',
frame: {selector: 'frame1-non-existent', frame: {selector: 'frame1-non-existent--element1'}},
})
assert.ok(Array.isArray(elements))
assert.strictEqual(elements.length, 0)
})
it('getContextElement()', async () => {

@@ -169,0 +201,0 @@ const mainContext = context

import assert from 'assert'
import {Driver} from '../../src/index'
import {Driver, MockDriver, fake} from '../../src/index'
const MockDriver = require('../fixtures/mock-driver')
const spec = require('../fixtures/spec-driver')
const logger = {log: () => null as any, warn: () => null as any, error: () => null as any}
describe('driver', () => {
let mock: any, driver: Driver<any, any, any, any>
let mock: MockDriver, driver: Driver<fake.Driver, fake.Context, fake.Element, fake.Selector>

@@ -46,3 +43,3 @@ before(async () => {

])
driver = new Driver({logger, spec, driver: mock})
driver = new Driver({logger, spec: fake.spec, driver: mock})
await driver.init()

@@ -331,3 +328,3 @@ })

before(async () => {
driver = new Driver({logger, spec, driver: new MockDriver({device: {isNative: true}})})
driver = new Driver({logger, spec: fake.spec, driver: new MockDriver({device: {isNative: true}})})
await driver.init()

@@ -349,3 +346,3 @@ })

logger,
spec,
spec: fake.spec,
driver: new MockDriver({

@@ -384,3 +381,3 @@ device: {isNative: true, name: 'MobilePhone'},

logger,
spec,
spec: fake.spec,
driver: new MockDriver({device: {isNative: true}}),

@@ -417,3 +414,3 @@ })

before(async () => {
driver = new Driver({logger, spec, driver: new MockDriver({device: {isNative: true}})})
driver = new Driver({logger, spec: fake.spec, driver: new MockDriver({device: {isNative: true}})})
await driver.init()

@@ -426,3 +423,3 @@ })

logger,
spec,
spec: fake.spec,
driver: new MockDriver({

@@ -463,3 +460,3 @@ ua: null,

logger,
spec,
spec: fake.spec,
driver: new MockDriver({

@@ -466,0 +463,0 @@ ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1',

@@ -9,14 +9,17 @@ {

"sourceMap": false,
"allowJs": true,
"target": "ES2017",
"module": "commonjs",
"target": "es2017",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"downlevelIteration": true,
"esModuleInterop": true,
"stripInternal": false,
"experimentalDecorators": true,
"esModuleInterop": true
"removeComments": false,
},
"exclude" : ["test/**/*.spec.ts", "types/**/*"],
"ts-node": {
"transpileOnly": true
},
"exclude" : ["dist", "types", "test"],
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc