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.3.0 to 1.3.1

dist/capabilities.js

11

CHANGELOG.md

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

## 1.3.1 - 2021/11/14
- add in-house capability parsing and system bars size handling mechanisms
- adjust scrolling algorithm on native devices
- support cookies
- updated to @applitools/types@1.0.20 (from 1.0.19)
## 1.3.0 - 2021/11/10

@@ -11,2 +18,6 @@

## 1.3.0 - 2021/11/10
- updated to @applitools/types@1.0.19 (from 1.0.18)
## 1.2.7 - 2021/10/30

@@ -13,0 +24,0 @@

@@ -440,2 +440,9 @@ "use strict";

}
async getCookies() {
var _a, _b;
if (this.driver.isNative)
return [];
await this.focus();
return (_b = (_a = this._spec) === null || _a === void 0 ? void 0 : _a.getCookies(this.target, true)) !== null && _b !== void 0 ? _b : [];
}
async preserveInnerOffset() {

@@ -442,0 +449,0 @@ this._state.innerOffset = await this.getInnerOffset();

57

dist/driver.js

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

const user_agent_1 = require("./user-agent");
const capabilities_1 = require("./capabilities");
const snippets = require('@applitools/snippets');

@@ -129,19 +130,39 @@ // eslint-disable-next-line

async init() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
this._driverInfo = await ((_b = (_a = this._spec).getDriverInfo) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
var _s, _t, _u, _v, _w, _x;
const capabilities = await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target));
this._logger.log('Driver capabilities', capabilities);
const capabilitiesInfo = capabilities ? capabilities_1.parseCapabilities(capabilities) : undefined;
const driverInfo = await ((_d = (_c = this._spec).getDriverInfo) === null || _d === void 0 ? void 0 : _d.call(_c, this.target));
this._driverInfo = Object.assign(Object.assign({}, capabilitiesInfo), driverInfo);
if (this.isWeb) {
const userAgent = (_d = (_c = this._driverInfo) === null || _c === void 0 ? void 0 : _c.userAgent) !== null && _d !== void 0 ? _d : (await this.execute(snippets.getUserAgent));
const pixelRatio = (_f = (_e = this._driverInfo) === null || _e === void 0 ? void 0 : _e.pixelRatio) !== null && _f !== void 0 ? _f : (await this.execute(snippets.getPixelRatio));
const userAgentInfo = userAgent ? user_agent_1.parseUserAgent(userAgent) : {};
this._driverInfo = Object.assign(Object.assign({}, this._driverInfo), { isMobile: (_h = (_g = this._driverInfo) === null || _g === void 0 ? void 0 : _g.isMobile) !== null && _h !== void 0 ? _h : ['iOS', 'Android'].includes(userAgentInfo.platformName), platformName: ((_j = this._driverInfo) === null || _j === void 0 ? void 0 : _j.isMobile)
? (_l = (_k = this._driverInfo) === null || _k === void 0 ? void 0 : _k.platformName) !== null && _l !== void 0 ? _l : userAgentInfo.platformName
: (_m = userAgentInfo.platformName) !== null && _m !== void 0 ? _m : (_o = this._driverInfo) === null || _o === void 0 ? void 0 : _o.platformName, platformVersion: ((_p = this._driverInfo) === null || _p === void 0 ? void 0 : _p.isMobile)
? (_r = (_q = this._driverInfo) === null || _q === void 0 ? void 0 : _q.platformVersion) !== null && _r !== void 0 ? _r : userAgentInfo.platformVersion
: (_s = userAgentInfo.platformVersion) !== null && _s !== void 0 ? _s : (_t = this._driverInfo) === null || _t === void 0 ? void 0 : _t.platformVersion, browserName: (_u = userAgentInfo.browserName) !== null && _u !== void 0 ? _u : (_v = this._driverInfo) === null || _v === void 0 ? void 0 : _v.browserName, browserVersion: (_w = userAgentInfo.browserVersion) !== null && _w !== void 0 ? _w : (_x = this._driverInfo) === null || _x === void 0 ? void 0 : _x.browserVersion, userAgent,
pixelRatio });
(_e = (_s = this._driverInfo).pixelRatio) !== null && _e !== void 0 ? _e : (_s.pixelRatio = await this.execute(snippets.getPixelRatio));
(_f = (_t = this._driverInfo).userAgent) !== null && _f !== void 0 ? _f : (_t.userAgent = await this.execute(snippets.getUserAgent));
if (this._driverInfo.userAgent) {
const userAgentInfo = user_agent_1.parseUserAgent(this._driverInfo.userAgent);
this._driverInfo.browserName = (_g = userAgentInfo.browserName) !== null && _g !== void 0 ? _g : this._driverInfo.browserName;
this._driverInfo.browserVersion = (_h = userAgentInfo.browserVersion) !== null && _h !== void 0 ? _h : this._driverInfo.browserVersion;
if (!this._driverInfo.isMobile) {
(_j = (_u = this._driverInfo).platformName) !== null && _j !== void 0 ? _j : (_u.platformName = userAgentInfo.platformName);
(_k = (_v = this._driverInfo).platformVersion) !== null && _k !== void 0 ? _k : (_v.platformVersion = userAgentInfo.platformVersion);
}
else {
this._driverInfo.platformName = (_l = userAgentInfo.platformName) !== null && _l !== void 0 ? _l : this._driverInfo.platformName;
this._driverInfo.platformVersion = (_m = userAgentInfo.platformVersion) !== null && _m !== void 0 ? _m : this._driverInfo.platformVersion;
}
}
(_o = (_w = this._driverInfo).features) !== null && _o !== void 0 ? _o : (_w.features = {});
(_p = (_x = this._driverInfo.features).allCookies) !== null && _p !== void 0 ? _p : (_x.allCookies = /chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile);
}
else {
if (this.isAndroid) {
this._driverInfo.statusBarHeight = this._driverInfo.statusBarHeight / this.pixelRatio;
this._driverInfo.navigationBarHeight = this._driverInfo.navigationBarHeight / this.pixelRatio;
if (this.isNative) {
const barsHeight = await ((_r = (_q = this._spec).getBarsHeight) === null || _r === void 0 ? void 0 : _r.call(_q, this.target).catch(() => undefined));
if (barsHeight) {
this._driverInfo.statusBarHeight = Math.max(barsHeight.statusBarHeight, driverInfo.statusBarHeight);
this._driverInfo.navigationBarHeight = Math.max(barsHeight.navigationBarHeight, driverInfo.navigationBarHeight);
}
if (this.isAndroid) {
this._driverInfo.statusBarHeight /= this.pixelRatio;
this._driverInfo.navigationBarHeight /= this.pixelRatio;
}
}

@@ -156,3 +177,3 @@ if (!this._driverInfo.viewportSize) {

}
this._logger.log('Driver initialized', this._driverInfo);
this._logger.log('Combined driver info', this._driverInfo);
return this;

@@ -418,2 +439,8 @@ }

}
async getCookies() {
var _a, _b;
if (this.isNative || !this.features.allCookies)
return [];
return (_b = (_a = this._spec) === null || _a === void 0 ? void 0 : _a.getCookies(this.target)) !== null && _b !== void 0 ? _b : [];
}
async getTitle() {

@@ -420,0 +447,0 @@ if (this.isNative)

@@ -312,3 +312,4 @@ "use strict";

requiredOffset = offset;
remainingOffset = { x: -maxOffset.x, y: -maxOffset.y };
// if it has to be scrolled to the very beginning, then scroll maximum amount of pixels and a bit extra to be sure
remainingOffset = { x: -(maxOffset.x + 0), y: -(maxOffset.y + 0) };
}

@@ -318,3 +319,10 @@ else {

remainingOffset = utils.geometry.offsetNegative(requiredOffset, currentScrollOffset);
// if it has to be scrolled to the very end, then do a bit of extra scrolling to be sure
// if (requiredOffset.x === maxOffset.x) remainingOffset.x += 100
// if (requiredOffset.y === maxOffset.y) remainingOffset.y += 100
}
// if (requiredOffset.x === 0) remainingOffset.x -= 100
// if (requiredOffset.y === 0) remainingOffset.y -= 100
// if (requiredOffset.x === maxOffset.x) remainingOffset.x += 100
// if (requiredOffset.y === maxOffset.y) remainingOffset.y += 100
if (this.driver.isAndroid) {

@@ -335,3 +343,3 @@ remainingOffset = utils.geometry.scale(remainingOffset, this.driver.pixelRatio);

}
const yPadding = Math.floor(scrollableRegion.height * 0.1);
const yPadding = Math.floor(scrollableRegion.height * 0.08);
const xCenter = Math.floor(scrollableRegion.x + scrollableRegion.width / 2); // 0

@@ -338,0 +346,0 @@ const yTop = scrollableRegion.y + yPadding;

@@ -0,1 +1,5 @@

"use strict";
// @ts-nocheck
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockDriver = void 0;
const { inspect } = require('util');

@@ -21,3 +25,4 @@ const utils = require('@applitools/utils');

class MockDriver {
constructor({ viewport = { width: 1000, height: 1000 }, device, platform, browser, ua } = {}) {
constructor(options = {}) {
const { viewport = { width: 1000, height: 1000 }, device, platform, browser, ua } = options;
this._device = device;

@@ -340,2 +345,2 @@ this._platform = platform;

}
module.exports = { MockDriver };
exports.MockDriver = MockDriver;

@@ -1,66 +0,104 @@

const utils = require('@applitools/utils');
const spec = {
isDriver(driver) {
return driver && driver.constructor.name === 'MockDriver';
},
isElement(element) {
return utils.types.has(element, 'id');
},
isSelector(selector) {
return utils.types.isString(selector) || utils.types.has(selector, ['using', 'value']);
},
transformSelector(selector) {
return selector.selector || selector;
},
isStaleElementError() {
return false;
},
isEqualElements(_driver, element1, element2) {
return element1.id === element2.id;
},
executeScript(driver, script, ...args) {
return driver.executeScript(script, args);
},
findElement(driver, selector, parent) {
return driver.findElement(selector.selector || selector, parent);
},
findElements(driver, selector, parent) {
return driver.findElements(selector.selector || selector, parent);
},
mainContext(driver) {
return driver.switchToFrame(null);
},
parentContext(driver) {
return driver.switchToParentFrame();
},
childContext(driver, reference) {
return driver.switchToFrame(reference);
},
takeScreenshot(driver) {
return driver.takeScreenshot();
},
getDriverInfo(driver) {
return driver.info;
},
async getWindowSize(driver) {
const rect = await driver.getWindowRect();
return rect;
},
async setWindowSize(driver, size) {
await driver.setWindowRect(size);
},
async getUrl(driver) {
if (this._isNative)
return null;
return driver.getUrl();
},
async getTitle(driver) {
if (this._isNative)
return null;
return driver.getTitle();
},
async visit(driver, url) {
await driver.visit(url);
},
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
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 __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;
};
module.exports = { spec };
Object.defineProperty(exports, "__esModule", { value: true });
exports.visit = exports.getTitle = exports.getUrl = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.takeScreenshot = exports.childContext = exports.parentContext = exports.mainContext = exports.findElements = exports.findElement = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.transformSelector = exports.isSelector = exports.isElement = exports.isDriver = void 0;
const utils = __importStar(require("@applitools/utils"));
function isDriver(driver) {
return driver && driver.constructor.name === 'MockDriver';
}
exports.isDriver = isDriver;
function isElement(element) {
return utils.types.has(element, 'id');
}
exports.isElement = isElement;
function isSelector(selector) {
return utils.types.isString(selector) || utils.types.has(selector, ['using', 'value']);
}
exports.isSelector = isSelector;
function transformSelector(selector) {
return utils.types.has(selector, 'selector') ? selector.selector : selector;
}
exports.transformSelector = transformSelector;
function isStaleElementError() {
return false;
}
exports.isStaleElementError = isStaleElementError;
async function isEqualElements(_driver, element1, element2) {
return element1.id === element2.id;
}
exports.isEqualElements = isEqualElements;
async function executeScript(driver, script, arg) {
return driver.executeScript(script, [arg]);
}
exports.executeScript = executeScript;
async function findElement(driver, selector, parent) {
return driver.findElement(selector, parent);
}
exports.findElement = findElement;
async function findElements(driver, selector, parent) {
return driver.findElements(selector, parent);
}
exports.findElements = findElements;
async function mainContext(driver) {
return driver.switchToFrame(null);
}
exports.mainContext = mainContext;
async function parentContext(driver) {
return driver.switchToParentFrame();
}
exports.parentContext = parentContext;
async function childContext(driver, element) {
return driver.switchToFrame(element);
}
exports.childContext = childContext;
async function takeScreenshot(driver) {
return driver.takeScreenshot();
}
exports.takeScreenshot = takeScreenshot;
async function getDriverInfo(driver) {
return driver.info;
}
exports.getDriverInfo = getDriverInfo;
async function getWindowSize(driver) {
const rect = await driver.getWindowRect();
return rect;
}
exports.getWindowSize = getWindowSize;
async function setWindowSize(driver, size) {
await driver.setWindowRect(size);
}
exports.setWindowSize = setWindowSize;
async function getUrl(driver) {
if (this._isNative)
return null;
return driver.getUrl();
}
exports.getUrl = getUrl;
async function getTitle(driver) {
if (this._isNative)
return null;
return driver.getTitle();
}
exports.getTitle = getTitle;
async function visit(driver, url) {
await driver.visit(url);
}
exports.visit = visit;

@@ -9,23 +9,8 @@ "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("./element"), exports);
__exportStar(require("./fake/mock-driver"), exports);
exports.fake = __importStar(require("./fake/spec-driver"));
{
"name": "@applitools/driver",
"version": "1.3.0",
"version": "1.3.1",
"description": "Applitools universal framework wrapper",

@@ -29,5 +29,11 @@ "keywords": [

"types": "./types/index.d.ts",
"directories": {
"lib": "./src",
"test": "./test"
"exports": {
".": {
"default": "./dist/index.js",
"types": "./types/index.d.ts"
},
"./fake": {
"default": "./dist/fake/index.js",
"types": "./types/fake/index.d.ts"
}
},

@@ -39,3 +45,3 @@ "files": [

"scripts": {
"lint": "eslint '**/*.ts' '**/*.js'",
"lint": "eslint '**/*.ts'",
"build": "tsc",

@@ -55,3 +61,3 @@ "test": "mocha --no-timeouts -r ts-node/register ./test/**/*.spec.ts",

"@applitools/snippets": "2.1.7",
"@applitools/types": "1.0.19",
"@applitools/types": "1.0.20",
"@applitools/utils": "1.2.4"

@@ -58,0 +64,0 @@ },

@@ -67,2 +67,3 @@ import type * as types from '@applitools/types';

getRegionInViewport(region: types.Region): Promise<types.Region>;
getCookies(): Promise<types.Cookie[]>;
private preserveInnerOffset;

@@ -69,0 +70,0 @@ private preserveContextRegions;

@@ -58,2 +58,3 @@ /// <reference types="node" />

getOrientation(): Promise<'portrait' | 'landscape'>;
getCookies(): Promise<types.Cookie[]>;
getTitle(): Promise<string>;

@@ -60,0 +61,0 @@ getUrl(): Promise<string>;

@@ -1,32 +0,3 @@

/// <reference types="node" />
export class MockDriver {
constructor({ viewport, device, platform, browser, ua }?: {
viewport?: {
width: number;
height: number;
};
device: any;
platform: any;
browser: any;
ua: any;
});
_device: any;
_platform: any;
_browser: any;
_ua: any;
_window: {
title: string;
url: string;
rect: {
width: number;
height: number;
x: number;
y: number;
};
};
_methods: Map<any, any>;
_scripts: Map<any, any>;
_elements: Map<any, any>;
_contexts: Map<any, any>;
_contextId: any;
export declare class MockDriver {
constructor(options?: {});
mockScript(scriptMatcher: any, resultGenerator: any): void;

@@ -54,13 +25,8 @@ mockElement(selector: any, state: any): any;

findElements(selector: any, rootElement: any): Promise<any>;
switchToFrame(reference: any): Promise<MockDriver>;
switchToParentFrame(): Promise<MockDriver>;
getWindowRect(): Promise<{
width: number;
height: number;
x: number;
y: number;
}>;
switchToFrame(reference: any): Promise<this>;
switchToParentFrame(): Promise<this>;
getWindowRect(): Promise<any>;
setWindowRect(rect: any): Promise<void>;
getUrl(): Promise<string>;
getTitle(): Promise<string>;
getUrl(): Promise<any>;
getTitle(): Promise<any>;
visit(url: any): Promise<void>;

@@ -70,4 +36,2 @@ takeScreenshot(): Promise<void>;

toJSON(): string;
[inspect.custom](): string;
}
import { inspect } from "util";

@@ -1,40 +0,29 @@

export namespace spec {
function isDriver(driver: any): boolean;
function isDriver(driver: any): boolean;
function isElement(element: any): boolean;
function isElement(element: any): boolean;
function isSelector(selector: any): boolean;
function isSelector(selector: any): boolean;
function transformSelector(selector: any): any;
function transformSelector(selector: any): any;
function isStaleElementError(): boolean;
function isStaleElementError(): boolean;
function isEqualElements(_driver: any, element1: any, element2: any): boolean;
function isEqualElements(_driver: any, element1: any, element2: any): boolean;
function executeScript(driver: any, script: any, ...args: any[]): any;
function executeScript(driver: any, script: any, ...args: any[]): any;
function findElement(driver: any, selector: any, parent: any): any;
function findElement(driver: any, selector: any, parent: any): any;
function findElements(driver: any, selector: any, parent: any): any;
function findElements(driver: any, selector: any, parent: any): any;
function mainContext(driver: any): any;
function mainContext(driver: any): any;
function parentContext(driver: any): any;
function parentContext(driver: any): any;
function childContext(driver: any, reference: any): any;
function childContext(driver: any, reference: any): any;
function takeScreenshot(driver: any): any;
function takeScreenshot(driver: any): any;
function getDriverInfo(driver: any): any;
function getDriverInfo(driver: any): any;
function getWindowSize(driver: any): Promise<any>;
function getWindowSize(driver: any): Promise<any>;
function setWindowSize(driver: any, size: any): Promise<void>;
function setWindowSize(driver: any, size: any): Promise<void>;
function getUrl(driver: any): Promise<any>;
function getUrl(driver: any): Promise<any>;
function getTitle(driver: any): Promise<any>;
function getTitle(driver: any): Promise<any>;
function visit(driver: any, url: any): Promise<void>;
function visit(driver: any, url: any): Promise<void>;
}
/// <reference types="node" />
import type { Size, DriverInfo } from '@applitools/types';
export declare type Driver = any;
export declare type Element = any;
export declare type Selector = string | {
using: string;
value: string;
};
export declare function isDriver(driver: any): driver is Driver;
export declare function isElement(element: any): element is Element;
export declare function isSelector(selector: any): selector is Selector;
export declare function transformSelector(selector: Selector | {
selector: Selector;
}): Selector;
export declare function isStaleElementError(): boolean;
export declare function isEqualElements(_driver: Driver, element1: Element, element2: Element): Promise<boolean>;
export declare function executeScript(driver: Driver, script: ((arg: any) => any) | string, arg: any): Promise<any>;
export declare function findElement(driver: Driver, selector: Selector, parent?: Element): Promise<Element>;
export declare function findElements(driver: Driver, selector: Selector, parent?: Element): Promise<Element[]>;
export declare function mainContext(driver: Driver): Promise<Driver>;
export declare function parentContext(driver: Driver): Promise<Driver>;
export declare function childContext(driver: Driver, element: Element): Promise<Driver>;
export declare function takeScreenshot(driver: Driver): Promise<Buffer | string>;
export declare function getDriverInfo(driver: Driver): Promise<DriverInfo>;
export declare function getWindowSize(driver: Driver): Promise<Size>;
export declare function setWindowSize(driver: Driver, size: Size): Promise<void>;
export declare function getUrl(driver: Driver): Promise<string>;
export declare function getTitle(driver: Driver): Promise<string>;
export declare function visit(driver: Driver, url: string): Promise<void>;
export * from './driver';
export * from './context';
export * from './element';
export * from './fake/mock-driver';
export * as fake from './fake/spec-driver';
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