@applitools/driver
Advanced tools
Comparing version 1.11.3 to 1.11.4
@@ -343,2 +343,45 @@ "use strict"; | ||
} | ||
async executePoll(script, arg) { | ||
this._logger.log('Executing poll script'); | ||
const { main: mainScript, poll: pollScript } = utils.types.isString(script) || utils.types.isFunction(script) ? { main: script, poll: script } : script; | ||
const { main: mainArg, poll: pollArg, executionTimeout = 60000, pollTimeout = 1000, } = !utils.types.has(arg, ['main', 'poll']) ? { main: arg, poll: arg } : arg; | ||
let isExecutionTimedOut = false; | ||
const executionTimer = setTimeout(() => (isExecutionTimedOut = true), executionTimeout); | ||
try { | ||
let response = deserialize(await this.execute(mainScript, mainArg)); | ||
let chunks = ''; | ||
while (!isExecutionTimedOut) { | ||
if (response.status === 'ERROR') { | ||
throw new Error(`Error during execute poll script: '${response.error}'`); | ||
} | ||
else if (response.status === 'SUCCESS') { | ||
return response.value; | ||
} | ||
else if (response.status === 'SUCCESS_CHUNKED') { | ||
chunks += response.value; | ||
if (response.done) | ||
return deserialize(chunks); | ||
} | ||
else if (response.status === 'WIP') { | ||
await utils.general.sleep(pollTimeout); | ||
} | ||
this._logger.log('Polling...'); | ||
response = deserialize(await this.execute(pollScript, pollArg)); | ||
} | ||
throw new Error('Poll script execution is timed out'); | ||
} | ||
finally { | ||
clearTimeout(executionTimer); | ||
} | ||
function deserialize(json) { | ||
try { | ||
return JSON.parse(json); | ||
} | ||
catch (err) { | ||
const firstChars = json.slice(0, 100); | ||
const lastChars = json.slice(-100); | ||
throw new Error(`Response is not a valid JSON string. length: ${json.length}, first 100 chars: "${firstChars}", last 100 chars: "${lastChars}". error: ${err}`); | ||
} | ||
} | ||
} | ||
async getContextElement() { | ||
@@ -345,0 +388,0 @@ if (this.isMain) |
@@ -32,6 +32,7 @@ "use strict"; | ||
const user_agent_1 = require("./user-agent"); | ||
const user_agent_data_1 = require("./user-agent-data"); | ||
const capabilities_1 = require("./capabilities"); | ||
const snippets = __importStar(require("@applitools/snippets")); | ||
const utils = __importStar(require("@applitools/utils")); | ||
const specUtils = __importStar(require("./spec-utils")); | ||
const snippets = require('@applitools/snippets'); | ||
// eslint-disable-next-line | ||
@@ -139,9 +140,21 @@ class Driver { | ||
get isIOS() { | ||
var _a; | ||
return ((_a = this.platformName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'ios'; | ||
var _a, _b; | ||
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isIOS) !== null && _b !== void 0 ? _b : /iOS/i.test(this.platformName); | ||
} | ||
get isAndroid() { | ||
var _a; | ||
return ((_a = this.platformName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'android'; | ||
var _a, _b; | ||
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isAndroid) !== null && _b !== void 0 ? _b : /Android/i.test(this.platformName); | ||
} | ||
get isMac() { | ||
var _a, _b; | ||
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isMac) !== null && _b !== void 0 ? _b : /mac\s?OS/i.test(this.platformName); | ||
} | ||
get isWindows() { | ||
var _a, _b; | ||
return (_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isWindows) !== null && _b !== void 0 ? _b : /Windows/i.test(this.platformName); | ||
} | ||
get isChromium() { | ||
var _a, _b; | ||
return ((_b = (_a = this._driverInfo) === null || _a === void 0 ? void 0 : _a.isChromium) !== null && _b !== void 0 ? _b : (/(chrome)/i.test(this.browserName) || (/edge/i.test(this.browserName) && Number(this.browserVersion) > 44))); | ||
} | ||
get isIE() { | ||
@@ -157,4 +170,4 @@ return /(internet explorer|ie)/i.test(this.browserName); | ||
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, _y, _z, _0, _1, _2, _3, _4, _5, _6; | ||
var _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18; | ||
var _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34; | ||
// NOTE: this is here because saucelabs does not provide right capabilities for the first call | ||
@@ -174,24 +187,44 @@ await ((_b = (_a = this._spec).getCapabilities) === null || _b === void 0 ? void 0 : _b.call(_a, this.target)); | ||
if (this.isWeb) { | ||
(_h = (_7 = this._driverInfo).pixelRatio) !== null && _h !== void 0 ? _h : (_7.pixelRatio = await this.execute(snippets.getPixelRatio)); | ||
(_j = (_8 = this._driverInfo).viewportScale) !== null && _j !== void 0 ? _j : (_8.viewportScale = await this.execute(snippets.getViewportScale)); | ||
(_k = (_9 = this._driverInfo).userAgent) !== null && _k !== void 0 ? _k : (_9.userAgent = await this.execute(snippets.getUserAgent)); | ||
const browserInfo = await this.currentContext.executePoll(snippets.getBrowserInfo); | ||
(_h = (_19 = this._driverInfo).userAgent) !== null && _h !== void 0 ? _h : (_19.userAgent = browserInfo.userAgent); | ||
(_j = (_20 = this._driverInfo).pixelRatio) !== null && _j !== void 0 ? _j : (_20.pixelRatio = browserInfo.pixelRatio); | ||
(_k = (_21 = this._driverInfo).viewportScale) !== null && _k !== void 0 ? _k : (_21.viewportScale = browserInfo.viewportScale); | ||
if (browserInfo.userAgentData) { | ||
(_l = (_22 = this._driverInfo).isMobile) !== null && _l !== void 0 ? _l : (_22.isMobile = this._driverInfo.isMobile); | ||
(_m = (_23 = this._driverInfo).isChromium) !== null && _m !== void 0 ? _m : (_23.isChromium = this._driverInfo.isChromium); | ||
if (this.isChromium) { | ||
if (this.isWindows && Number.parseInt(this.browserVersion) >= 107) { | ||
this._driverInfo.platformVersion = (_o = browserInfo.platformVersion) !== null && _o !== void 0 ? _o : this._driverInfo.platformVersion; | ||
} | ||
else if (this.isMac && Number.parseInt(this.browserVersion) >= 90) { | ||
this._driverInfo.platformVersion = (_p = browserInfo.platformVersion) !== null && _p !== void 0 ? _p : this._driverInfo.platformVersion; | ||
} | ||
} | ||
} | ||
if (this._driverInfo.userAgent) { | ||
const userAgentInfo = (0, user_agent_1.parseUserAgent)(this._driverInfo.userAgent); | ||
this._driverInfo.browserName = (_l = userAgentInfo.browserName) !== null && _l !== void 0 ? _l : this._driverInfo.browserName; | ||
this._driverInfo.browserVersion = (_m = userAgentInfo.browserVersion) !== null && _m !== void 0 ? _m : this._driverInfo.browserVersion; | ||
const userAgentDataInfo = browserInfo.userAgentData && (0, user_agent_data_1.parseUserAgentData)(browserInfo.userAgentData); | ||
this._driverInfo.browserName = | ||
(_r = (_q = userAgentInfo.browserName) !== null && _q !== void 0 ? _q : userAgentDataInfo.browserName) !== null && _r !== void 0 ? _r : this._driverInfo.browserName; | ||
this._driverInfo.browserVersion = | ||
(_t = (_s = userAgentInfo.browserVersion) !== null && _s !== void 0 ? _s : userAgentDataInfo.browserVersion) !== null && _t !== void 0 ? _t : this._driverInfo.browserVersion; | ||
(_u = (_24 = this._driverInfo).isMobile) !== null && _u !== void 0 ? _u : (_24.isMobile = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isMobile); | ||
(_v = (_25 = this._driverInfo).isChromium) !== null && _v !== void 0 ? _v : (_25.isChromium = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.isChromium); | ||
if (this._driverInfo.isMobile) { | ||
(_o = (_10 = this._driverInfo).platformName) !== null && _o !== void 0 ? _o : (_10.platformName = userAgentInfo.platformName); | ||
(_p = (_11 = this._driverInfo).platformVersion) !== null && _p !== void 0 ? _p : (_11.platformVersion = userAgentInfo.platformVersion); | ||
(_w = (_26 = this._driverInfo).platformName) !== null && _w !== void 0 ? _w : (_26.platformName = (_x = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _x !== void 0 ? _x : userAgentInfo.platformName); | ||
(_y = (_27 = this._driverInfo).platformVersion) !== null && _y !== void 0 ? _y : (_27.platformVersion = (_z = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _z !== void 0 ? _z : userAgentInfo.platformVersion); | ||
} | ||
else { | ||
this._driverInfo.platformName = (_q = userAgentInfo.platformName) !== null && _q !== void 0 ? _q : this._driverInfo.platformName; | ||
this._driverInfo.platformVersion = (_r = userAgentInfo.platformVersion) !== null && _r !== void 0 ? _r : this._driverInfo.platformVersion; | ||
this._driverInfo.platformName = | ||
(_1 = (_0 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformName) !== null && _0 !== void 0 ? _0 : userAgentInfo.platformName) !== null && _1 !== void 0 ? _1 : this._driverInfo.platformName; | ||
this._driverInfo.platformVersion = | ||
(_3 = (_2 = userAgentDataInfo === null || userAgentDataInfo === void 0 ? void 0 : userAgentDataInfo.platformVersion) !== null && _2 !== void 0 ? _2 : userAgentInfo.platformVersion) !== null && _3 !== void 0 ? _3 : this._driverInfo.platformVersion; | ||
} | ||
} | ||
if (!this._driverInfo.isMobile && (this.isAndroid || this.isIOS)) { | ||
if (!this.isMobile && (this.isAndroid || this.isIOS)) { | ||
this._driverInfo.isMobile = true; | ||
this._driverInfo.isEmulation = this._driverInfo.isChrome; | ||
} | ||
(_s = (_12 = this._driverInfo).features) !== null && _s !== void 0 ? _s : (_12.features = {}); | ||
(_t = (_13 = this._driverInfo.features).allCookies) !== null && _t !== void 0 ? _t : (_13.allCookies = this._driverInfo.isChrome || (/chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile)); | ||
(_4 = (_28 = this._driverInfo).features) !== null && _4 !== void 0 ? _4 : (_28.features = {}); | ||
(_5 = (_29 = this._driverInfo.features).allCookies) !== null && _5 !== void 0 ? _5 : (_29.allCookies = this._driverInfo.isChrome || (/chrome/i.test(this._driverInfo.browserName) && !this._driverInfo.isMobile)); | ||
} | ||
@@ -201,4 +234,4 @@ else { | ||
let windowSize = await this._spec.getWindowSize(this.target); | ||
(_u = (_14 = this._driverInfo).displaySize) !== null && _u !== void 0 ? _u : (_14.displaySize = windowSize); | ||
if (((_v = this.orientation) === null || _v === void 0 ? void 0 : _v.startsWith('landscape')) && | ||
(_6 = (_30 = this._driverInfo).displaySize) !== null && _6 !== void 0 ? _6 : (_30.displaySize = windowSize); | ||
if (((_7 = this.orientation) === null || _7 === void 0 ? void 0 : _7.startsWith('landscape')) && | ||
this._driverInfo.displaySize.height > this._driverInfo.displaySize.width) { | ||
@@ -212,3 +245,3 @@ this._driverInfo.displaySize = { | ||
// bar sizes could be extracted only on android | ||
const systemBars = await ((_x = (_w = this._spec).getSystemBars) === null || _x === void 0 ? void 0 : _x.call(_w, this.target).catch(() => null)); | ||
const systemBars = await ((_9 = (_8 = this._spec).getSystemBars) === null || _9 === void 0 ? void 0 : _9.call(_8, this.target).catch(() => null)); | ||
const { statusBar, navigationBar } = systemBars !== null && systemBars !== void 0 ? systemBars : {}; | ||
@@ -220,3 +253,3 @@ if (statusBar === null || statusBar === void 0 ? void 0 : statusBar.visible) { | ||
if (statusBarSize < this._driverInfo.displaySize.height) { | ||
this._driverInfo.statusBarSize = Math.max((_y = this._driverInfo.statusBarSize) !== null && _y !== void 0 ? _y : 0, statusBarSize); | ||
this._driverInfo.statusBarSize = Math.max((_10 = this._driverInfo.statusBarSize) !== null && _10 !== void 0 ? _10 : 0, statusBarSize); | ||
} | ||
@@ -230,7 +263,7 @@ } | ||
// navigation bar size could be its height or width depending on screen orientation | ||
const navigationBarSize = navigationBar[((_z = this.orientation) === null || _z === void 0 ? void 0 : _z.startsWith('landscape')) ? 'width' : 'height']; | ||
const navigationBarSize = navigationBar[((_11 = this.orientation) === null || _11 === void 0 ? void 0 : _11.startsWith('landscape')) ? 'width' : 'height']; | ||
// when navigation bar is invisible on android it returns navigation bar size equal to display size | ||
if (navigationBarSize < | ||
this._driverInfo.displaySize[((_0 = this.orientation) === null || _0 === void 0 ? void 0 : _0.startsWith('landscape')) ? 'width' : 'height']) { | ||
this._driverInfo.navigationBarSize = Math.max((_1 = this._driverInfo.navigationBarSize) !== null && _1 !== void 0 ? _1 : 0, navigationBarSize); | ||
this._driverInfo.displaySize[((_12 = this.orientation) === null || _12 === void 0 ? void 0 : _12.startsWith('landscape')) ? 'width' : 'height']) { | ||
this._driverInfo.navigationBarSize = Math.max((_13 = this._driverInfo.navigationBarSize) !== null && _13 !== void 0 ? _13 : 0, navigationBarSize); | ||
} | ||
@@ -242,13 +275,13 @@ else { | ||
// bar sizes have to be scaled on android | ||
(_15 = this._driverInfo).statusBarSize && (_15.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio); | ||
(_16 = this._driverInfo).navigationBarSize && (_16.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio); | ||
(_31 = this._driverInfo).statusBarSize && (_31.statusBarSize = this._driverInfo.statusBarSize / this.pixelRatio); | ||
(_32 = this._driverInfo).navigationBarSize && (_32.navigationBarSize = this._driverInfo.navigationBarSize / this.pixelRatio); | ||
windowSize = utils.geometry.scale(windowSize, 1 / this.pixelRatio); | ||
(_17 = this._driverInfo).displaySize && (_17.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio)); | ||
(_33 = this._driverInfo).displaySize && (_33.displaySize = utils.geometry.scale(this._driverInfo.displaySize, 1 / this.pixelRatio)); | ||
} | ||
if (this.isIOS) { | ||
if ((_2 = this.orientation) === null || _2 === void 0 ? void 0 : _2.startsWith('landscape')) | ||
if ((_14 = this.orientation) === null || _14 === void 0 ? void 0 : _14.startsWith('landscape')) | ||
this._driverInfo.statusBarSize = 0; | ||
} | ||
// calculate viewport location | ||
(_3 = (_18 = this._driverInfo).viewportLocation) !== null && _3 !== void 0 ? _3 : (_18.viewportLocation = { | ||
(_15 = (_34 = this._driverInfo).viewportLocation) !== null && _15 !== void 0 ? _15 : (_34.viewportLocation = { | ||
x: this.orientation === 'landscape' ? this.navigationBarSize : 0, | ||
@@ -262,3 +295,3 @@ y: this.statusBarSize, | ||
if (this.isAndroid) { | ||
this._driverInfo.viewportSize[((_4 = this.orientation) === null || _4 === void 0 ? void 0 : _4.startsWith('landscape')) ? 'width' : 'height'] -= | ||
this._driverInfo.viewportSize[((_16 = this.orientation) === null || _16 === void 0 ? void 0 : _16.startsWith('landscape')) ? 'width' : 'height'] -= | ||
this.navigationBarSize; | ||
@@ -286,3 +319,3 @@ } | ||
// init helper lib | ||
if (!((_5 = this._customConfig) === null || _5 === void 0 ? void 0 : _5.disableHelper)) { | ||
if (!((_17 = this._customConfig) === null || _17 === void 0 ? void 0 : _17.disableHelper)) { | ||
this._helper = this.isIOS | ||
@@ -292,3 +325,3 @@ ? await helper_ios_1.HelperIOS.make({ spec: this._spec, driver: this, logger: this._logger }) | ||
} | ||
this._logger.log(`Helper set to ${(_6 = this._helper) === null || _6 === void 0 ? void 0 : _6.name}`); | ||
this._logger.log(`Helper set to ${(_18 = this._helper) === null || _18 === void 0 ? void 0 : _18.name}`); | ||
} | ||
@@ -295,0 +328,0 @@ this._logger.log('Combined driver info', this._driverInfo); |
@@ -120,12 +120,13 @@ "use strict"; | ||
}); | ||
this.mockScript(snippets.getPixelRatio, () => { | ||
return 1; | ||
}); | ||
this.mockScript(snippets.getShadowRoot, ([element]) => { | ||
return element; | ||
}); | ||
this.mockScript(snippets.getUserAgent, () => { | ||
if (this._ua !== undefined) | ||
return this._ua; | ||
return this.info.isMobile ? DEFAULT_MOBILE_UA : DEFAULT_DESKTOP_UA; | ||
this.mockScript(snippets.getBrowserInfo, () => { | ||
return JSON.stringify({ | ||
status: 'SUCCESS', | ||
value: { | ||
userAgent: this._ua !== undefined ? this._ua : this.info.isMobile ? DEFAULT_MOBILE_UA : DEFAULT_DESKTOP_UA, | ||
pixelRatio: 1, | ||
}, | ||
}); | ||
}); | ||
@@ -132,0 +133,0 @@ this.mockScript(snippets.getViewportSize, () => { |
{ | ||
"name": "@applitools/driver", | ||
"version": "1.11.3", | ||
"version": "1.11.4", | ||
"description": "Applitools universal framework wrapper", | ||
@@ -90,5 +90,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@applitools/logger": "1.1.28", | ||
"@applitools/snippets": "2.4.6", | ||
"@applitools/utils": "1.3.14", | ||
"@applitools/logger": "1.1.29", | ||
"@applitools/snippets": "2.4.7", | ||
"@applitools/utils": "1.3.15", | ||
"semver": "7.3.7" | ||
@@ -95,0 +95,0 @@ }, |
@@ -59,2 +59,11 @@ import type { Location, Size, Region } from '@applitools/utils'; | ||
execute(script: ((args: any) => any) | string, arg?: any): Promise<any>; | ||
executePoll(script: ((arg: any) => any) | string | { | ||
main: ((arg: any) => any) | string; | ||
poll: ((arg: any) => any) | string; | ||
}, arg?: any | { | ||
main: any; | ||
poll: any; | ||
executionTimeout?: number; | ||
pollTimeout?: number; | ||
}): Promise<any>; | ||
getContextElement(): Promise<Element<TDriver, TContext, TElement, TSelector>>; | ||
@@ -61,0 +70,0 @@ getScrollingElement(): Promise<Element<TDriver, TContext, TElement, TSelector>>; |
@@ -58,2 +58,5 @@ /// <reference types="node" /> | ||
get isAndroid(): boolean; | ||
get isMac(): boolean; | ||
get isWindows(): boolean; | ||
get isChromium(): boolean; | ||
get isIE(): boolean; | ||
@@ -60,0 +63,0 @@ get isEdgeLegacy(): boolean; |
@@ -24,2 +24,3 @@ /// <reference types="node" /> | ||
isChrome?: boolean; | ||
isChromium?: boolean; | ||
isEmulation?: boolean; | ||
@@ -30,2 +31,4 @@ isMobile?: boolean; | ||
isIOS?: boolean; | ||
isMac?: boolean; | ||
isWindows?: boolean; | ||
isWebView?: boolean; | ||
@@ -32,0 +35,0 @@ features?: { |
238490
39
3885
+ Added@applitools/logger@1.1.29(transitive)
+ Added@applitools/snippets@2.4.7(transitive)
+ Added@applitools/utils@1.3.15(transitive)
- Removed@applitools/logger@1.1.28(transitive)
- Removed@applitools/snippets@2.4.6(transitive)
- Removed@applitools/utils@1.3.14(transitive)
Updated@applitools/logger@1.1.29
Updated@applitools/snippets@2.4.7
Updated@applitools/utils@1.3.15