eyes.selenium
Advanced tools
Comparing version 3.7.0 to 3.8.0
{ | ||
"name": "eyes.selenium", | ||
"version": "3.7.0", | ||
"version": "3.8.0", | ||
"description": "Applitools Eyes SDK For Selenium JavaScript WebDriver", | ||
@@ -48,12 +48,12 @@ "keywords": [ | ||
"dependencies": { | ||
"eyes.sdk": "^3.7.0", | ||
"eyes.utils": "^3.6.4" | ||
"eyes.sdk": "^3.8.0", | ||
"eyes.utils": "^3.8.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "*", | ||
"chromedriver": "^75.0.0", | ||
"chromedriver": "^75.1.0", | ||
"mocha": "^6.1.4", | ||
"protractor": "^5.4.2", | ||
"selenium-webdriver": "^3.6.0", | ||
"typescript": "^2.9.2" | ||
"typescript": "^3.5.3" | ||
}, | ||
@@ -76,3 +76,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "48a4d4b11497ecced8a5b52226150a6eb2b7485e" | ||
"gitHead": "9187d7271ee8b54668272841c6e8fdc2dd28bb1f" | ||
} |
'use strict'; | ||
const { By } = require('selenium-webdriver'); | ||
const { OSNames } = require('eyes.utils'); | ||
@@ -8,2 +9,63 @@ const { ImageProvider, MutableImage } = require('eyes.sdk'); | ||
/** | ||
* @private | ||
* @ignore | ||
*/ | ||
class DeviceData { | ||
constructor(width, height, vpWidth, vpHeight) { | ||
this.width = width; | ||
this.height = height; | ||
this.vpWidth = vpWidth; | ||
this.vpHeight = vpHeight; | ||
} | ||
hashCode() { | ||
return this.width * 100000 + this.height * 1000 + this.vpWidth * 100 + this.vpHeight; | ||
} | ||
} | ||
/** | ||
* @private | ||
* @ignore | ||
*/ | ||
class RegionAndVersion { | ||
constructor(version, region) { | ||
this.majorVersion = version; | ||
this.region = region; | ||
} | ||
getMajorVersion() { | ||
return this.majorVersion; | ||
} | ||
getRegion() { | ||
return this.region.getObject(); | ||
} | ||
} | ||
/** | ||
* @private | ||
* @ignore | ||
*/ | ||
class Region { | ||
constructor(left, top, width, height) { | ||
this.left = left; | ||
this.top = top; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
getObject() { | ||
return { | ||
left: this.left, | ||
top: this.top, | ||
width: this.width, | ||
height: this.height | ||
}; | ||
} | ||
} | ||
/** | ||
* @ignore | ||
*/ | ||
class SafariScreenshotImageProvider extends ImageProvider { | ||
@@ -23,2 +85,5 @@ /** | ||
this._userAgent = userAgent; | ||
/** @type {Map<int, RegionAndVersion>} */ | ||
this._devicesRegions = undefined; | ||
this._jsExecutor = tsInstance; | ||
@@ -52,4 +117,4 @@ } | ||
viewportSize = { | ||
width: Math.ceil(originalViewportSize.width * scaleRatio), | ||
height: Math.ceil(originalViewportSize.height * scaleRatio) | ||
width: Math.ceil(originalViewportSize.width * scaleRatio), | ||
height: Math.ceil(originalViewportSize.height * scaleRatio) | ||
}; | ||
@@ -60,64 +125,25 @@ | ||
if (that._userAgent.getOS() === OSNames.IOS) { | ||
let topBarHeight = 20; | ||
let leftBarWidth = 0; | ||
let bottomBarHeight = 44; | ||
let rightBarWidth = 0; | ||
let urlBarHeight = 44; | ||
if (!this._devicesRegions) { | ||
this._initDeviceRegionsTable(); | ||
} | ||
const imageWidth = image.getWidth(); | ||
const imageHeight = image.getHeight(); | ||
const displayLogicalWidth = Math.ceil(imageWidth / scaleRatio); | ||
const displayLogicalHeight = Math.ceil(imageHeight / scaleRatio); | ||
that._logger.verbose(`physical device pixel size: ${imageWidth} x ${imageHeight}`); | ||
that._logger.verbose(`physical device logical size: ${displayLogicalWidth} x ${displayLogicalHeight}`); | ||
this._logger.verbose(`physical device pixel size: ${imageWidth} x ${imageHeight}`); | ||
if (displayLogicalHeight === 736 && displayLogicalWidth === 414) { // iPhone 5.5 inch | ||
that._logger.verbose('iPhone 5.5 inch detected'); | ||
topBarHeight = 18; | ||
} else if (displayLogicalHeight === 812 && displayLogicalWidth === 375) { // iPhone 5.8 inch p | ||
that._logger.verbose('iPhone 5.8 inch portrait detected'); | ||
topBarHeight = 44; | ||
bottomBarHeight = 83; | ||
} else if (displayLogicalWidth === 812 && displayLogicalHeight === 375) { // iPhone 5.8 inch l | ||
that._logger.verbose('iPhone 5.8 inch landscape detected'); | ||
leftBarWidth = 44; | ||
rightBarWidth = 44; | ||
} | ||
const deviceData = new DeviceData(imageWidth, imageHeight, originalViewportSize.width, originalViewportSize.height); | ||
if (displayLogicalHeight < displayLogicalWidth) { | ||
that._logger.verbose('landscape mode detected'); | ||
topBarHeight = 0; | ||
if (displayLogicalWidth === 812 && displayLogicalHeight === 375) { // on iPhone X crop the home indicator. | ||
bottomBarHeight = 15; | ||
if (this._devicesRegions.has(deviceData.hashCode())) { | ||
const majorVersion = parseInt(this._userAgent.getBrowserMajorVersion(), 10); | ||
this._logger.verbose('device model found in hash table'); | ||
const cropByVersion = this._devicesRegions.get(deviceData.hashCode()); | ||
if (cropByVersion.getMajorVersion() <= majorVersion) { | ||
return image.cropImage(cropByVersion.getRegion()); | ||
} else { | ||
bottomBarHeight = 0; | ||
this._logger.verbose('device version not found in list. returning original image.'); | ||
} | ||
// on iPhone 5.5 inch with Safari 10 in landscape mode crop the tabs bar. | ||
if (displayLogicalWidth === 736 && displayLogicalHeight === 414 && | ||
parseInt(that._userAgent.getBrowserMajorVersion(), 10) < 11) { | ||
topBarHeight = 33; | ||
} | ||
} else { | ||
this._logger.verbose('device not found in list. returning original image.'); | ||
} | ||
if (parseInt(that._userAgent.getBrowserMajorVersion(), 10) >= 11) { // Safari >= 11 | ||
that._logger.verbose('safari version 11 or higher detected'); | ||
urlBarHeight = 50; | ||
} | ||
viewportSize = { | ||
width: Math.ceil(imageWidth - (leftBarWidth + rightBarWidth) * scaleRatio), | ||
height: Math.ceil(imageHeight - (topBarHeight + urlBarHeight + bottomBarHeight) * scaleRatio) | ||
}; | ||
that._logger.verbose(`computed physical viewport size: ${viewportSize}`); | ||
that._logger.verbose('cropping IOS browser image'); | ||
return image.cropImage({ | ||
left: Math.ceil(leftBarWidth * scaleRatio), | ||
top: Math.ceil((topBarHeight + urlBarHeight) * scaleRatio), | ||
width: viewportSize.width, | ||
height: viewportSize.height | ||
}); | ||
} | ||
@@ -137,6 +163,6 @@ | ||
return promise.then(loc => image.cropImage({ | ||
left: loc.x * scaleRatio, | ||
top: loc.y * scaleRatio, | ||
width: viewportSize.width, | ||
height: viewportSize.height | ||
left: loc.x * scaleRatio, | ||
top: loc.y * scaleRatio, | ||
width: viewportSize.width, | ||
height: viewportSize.height | ||
})); | ||
@@ -149,4 +175,51 @@ } | ||
} | ||
_initDeviceRegionsTable() { | ||
this._devicesRegions = new Map(); | ||
// In JS, we need to maintain object reference if we want to use object as a key of Map. | ||
// But if we use primitive type, we don't need to. So, we call `hashCode` method to convert class to primitive | ||
this._devicesRegions.set(new DeviceData(828, 1792, 414, 719).hashCode(), new RegionAndVersion(12, new Region(0, 189, 828, 1436))); | ||
this._devicesRegions.set(new DeviceData(1792, 828, 808, 364).hashCode(), new RegionAndVersion(12, new Region(88, 101, 1616, 685))); | ||
this._devicesRegions.set(new DeviceData(1242, 2688, 414, 719).hashCode(), new RegionAndVersion(12, new Region(0, 283, 1242, 2155))); | ||
this._devicesRegions.set(new DeviceData(2688, 1242, 808, 364).hashCode(), new RegionAndVersion(12, new Region(132, 151, 2424, 1028))); | ||
this._devicesRegions.set(new DeviceData(1125, 2436, 375, 635).hashCode(), new RegionAndVersion(11, new Region(0, 283, 1125, 1903))); | ||
this._devicesRegions.set(new DeviceData(2436, 1125, 724, 325).hashCode(), new RegionAndVersion(11, new Region(132, 151, 2436, 930))); | ||
this._devicesRegions.set(new DeviceData(1242, 2208, 414, 622).hashCode(), new RegionAndVersion(11, new Region(0, 211, 1242, 1863))); | ||
this._devicesRegions.set(new DeviceData(2208, 1242, 736, 364).hashCode(), new RegionAndVersion(11, new Region(0, 151, 2208, 1090))); | ||
this._devicesRegions.set(new DeviceData(1242, 2208, 414, 628).hashCode(), new RegionAndVersion(10, new Region(0, 193, 1242, 1882))); | ||
this._devicesRegions.set(new DeviceData(2208, 1242, 736, 337).hashCode(), new RegionAndVersion(10, new Region(0, 231, 2208, 1010))); | ||
this._devicesRegions.set(new DeviceData(750, 1334, 375, 553).hashCode(), new RegionAndVersion(11, new Region(0, 141, 750, 1104))); | ||
this._devicesRegions.set(new DeviceData(1334, 750, 667, 325).hashCode(), new RegionAndVersion(11, new Region(0, 101, 1334, 648))); | ||
this._devicesRegions.set(new DeviceData(750, 1334, 375, 559).hashCode(), new RegionAndVersion(10, new Region(0, 129, 750, 1116))); | ||
this._devicesRegions.set(new DeviceData(1334, 750, 667, 331).hashCode(), new RegionAndVersion(10, new Region(0, 89, 1334, 660))); | ||
this._devicesRegions.set(new DeviceData(640, 1136, 320, 460).hashCode(), new RegionAndVersion(10, new Region(0, 129, 640, 918))); | ||
this._devicesRegions.set(new DeviceData(1136, 640, 568, 232).hashCode(), new RegionAndVersion(10, new Region(0, 89, 1136, 462))); | ||
this._devicesRegions.set(new DeviceData(1536, 2048, 768, 954).hashCode(), new RegionAndVersion(11, new Region(0, 141, 1536, 1907))); | ||
this._devicesRegions.set(new DeviceData(2048, 1536, 1024, 698).hashCode(), new RegionAndVersion(11, new Region(0, 141, 2048, 1395))); | ||
this._devicesRegions.set(new DeviceData(1536, 2048, 768, 922).hashCode(), new RegionAndVersion(11, new Region(0, 206, 1536, 1842))); | ||
this._devicesRegions.set(new DeviceData(2048, 1536, 1024, 666).hashCode(), new RegionAndVersion(11, new Region(0, 206, 2048, 1330))); | ||
this._devicesRegions.set(new DeviceData(1536, 2048, 768, 960).hashCode(), new RegionAndVersion(10, new Region(0, 129, 1536, 1919))); | ||
this._devicesRegions.set(new DeviceData(2048, 1536, 1024, 704).hashCode(), new RegionAndVersion(10, new Region(0, 129, 2048, 1407))); | ||
this._devicesRegions.set(new DeviceData(1536, 2048, 768, 928).hashCode(), new RegionAndVersion(10, new Region(0, 194, 1536, 1854))); | ||
this._devicesRegions.set(new DeviceData(2048, 1536, 1024, 672).hashCode(), new RegionAndVersion(10, new Region(0, 194, 2048, 1342))); | ||
this._devicesRegions.set(new DeviceData(2048, 2732, 1024, 1296).hashCode(), new RegionAndVersion(11, new Region(0, 141, 2048, 2591))); | ||
this._devicesRegions.set(new DeviceData(2732, 2048, 1366, 954).hashCode(), new RegionAndVersion(11, new Region(0, 141, 2732, 1907))); | ||
this._devicesRegions.set(new DeviceData(1668, 2224, 834, 1042).hashCode(), new RegionAndVersion(11, new Region(0, 141, 1668, 2083))); | ||
this._devicesRegions.set(new DeviceData(2224, 1668, 1112, 764).hashCode(), new RegionAndVersion(11, new Region(0, 141, 2224, 1527))); | ||
} | ||
} | ||
exports.SafariScreenshotImageProvider = SafariScreenshotImageProvider; |
@@ -215,3 +215,2 @@ (function () { | ||
Eyes.prototype.check = function (name, target) { | ||
ArgumentGuard.notNullOrEmpty(name, "Name"); | ||
ArgumentGuard.notNull(target, "Target"); | ||
@@ -342,2 +341,3 @@ | ||
ignoreCaret: target.getIgnoreCaret(), | ||
ignoreDisplacements: target.getIgnoreDisplacements(), | ||
ignore: target.getIgnoreRegions(), | ||
@@ -344,0 +344,0 @@ floating: target.getFloatingRegions(), |
@@ -26,2 +26,3 @@ (function () { | ||
this._ignoreCaret = null; | ||
this._ignoreDisplacements = null; | ||
this._ignoreRegions = []; | ||
@@ -98,2 +99,16 @@ this._floatingRegions = []; | ||
/** | ||
* @param {boolean} [ignoreDisplacements=true] | ||
* @return {Target} | ||
*/ | ||
Target.prototype.ignoreDisplacements = function (ignoreDisplacements) { | ||
if (ignoreDisplacements !== false) { | ||
ignoreDisplacements = true; | ||
} | ||
this._ignoreDisplacements = ignoreDisplacements; | ||
return this; | ||
}; | ||
//noinspection JSUnusedGlobalSymbols | ||
/** | ||
* @param {...(Region|webdriver.WebElement|EyesRemoteWebElement|webdriver.By| | ||
@@ -205,2 +220,9 @@ * {element: (webdriver.WebElement|EyesRemoteWebElement|webdriver.By)})} ignoreRegion | ||
/** | ||
* @return {boolean|null} | ||
*/ | ||
Target.prototype.getIgnoreDisplacements = function () { | ||
return this._ignoreDisplacements; | ||
}; | ||
/** | ||
* @return {Region[]} | ||
@@ -207,0 +229,0 @@ */ |
@@ -52,5 +52,5 @@ var webdriver = require('selenium-webdriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -52,5 +52,5 @@ var webdriver = require('selenium-webdriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -58,5 +58,5 @@ var webdriver = require('selenium-webdriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -64,3 +64,3 @@ 'use strict'; | ||
}).then(() => { | ||
eyes.abortIfNotClosed(); | ||
eyes.abort(); | ||
@@ -67,0 +67,0 @@ return driver.quit(); |
@@ -71,3 +71,3 @@ var SeleniumSDK = require('../../../index'); | ||
afterEach(function(done) { | ||
eyes.abortIfNotClosed().then(function () { | ||
eyes.abort().then(function () { | ||
done(); | ||
@@ -74,0 +74,0 @@ }); |
@@ -38,3 +38,3 @@ var SeleniumSDK = require('../../../index'); | ||
afterEach(function(done) { | ||
eyes.abortIfNotClosed().then(function () { | ||
eyes.abort().then(function () { | ||
done(); | ||
@@ -41,0 +41,0 @@ }); |
@@ -45,3 +45,3 @@ var SeleniumSDK = require('../../../index'); | ||
afterEach(function(done) { | ||
eyes.abortIfNotClosed().then(function () { | ||
eyes.abort().then(function () { | ||
done(); | ||
@@ -48,0 +48,0 @@ }); |
@@ -45,5 +45,5 @@ require('chromedriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -83,5 +83,5 @@ require('chromedriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -46,5 +46,5 @@ require('chromedriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -53,5 +53,5 @@ require('chromedriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -52,5 +52,5 @@ require('chromedriver'); | ||
return driver.quit().then(function () { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -97,5 +97,5 @@ 'use strict'; | ||
return driver.quit().then(function (value) { | ||
return eyes.abortIfNotClosed(); | ||
return eyes.abort(); | ||
}); | ||
}); | ||
}); |
@@ -668,2 +668,3 @@ /* Type definitions for eyes.selenium 3.6.0 */ | ||
ignoreCaret(ignoreCaret?: boolean): Target; | ||
ignoreDisplacements(ignoreDisplacements?: boolean): Target; | ||
ignore(...ignoreRegion: (Region|WebElement|EyesRemoteWebElement|By|{element: (WebElement|EyesRemoteWebElement|By)})[]): Target; | ||
@@ -680,2 +681,3 @@ floating(...floatingRegion: (FloatingRegion|FloatingElement)[]): Target; | ||
getIgnoreCaret(): boolean|null; | ||
getIgnoreDisplacements(): boolean|null; | ||
getIgnoreRegions(): Region[]; | ||
@@ -682,0 +684,0 @@ getIgnoreObjects(): {element: (WebElement|EyesRemoteWebElement|By)}[]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275262
5647
Updatedeyes.sdk@^3.8.0
Updatedeyes.utils@^3.8.0